Home > Backend Development > C#.Net Tutorial > What is the C# equivalent of the friend keyword in C++?

What is the C# equivalent of the friend keyword in C++?

PHPz
Release: 2023-09-15 10:53:02
forward
784 people have browsed it

C++ 中的friend 关键字在C# 中的等价物是什么?

Friends in C

#The friend function of a class is defined outside the scope of the class, but it has access to the class All private and protected members of . Although the prototype of a friend function appears in the class definition, a friend is not a member function.

Friends can be functions, function templates or member functions, or they can be classes or class templates. In this case, the entire class and all its members are friends.

C Equivalent to friends in C

#The closest equivalent is to create a nested class that will access the private members of the outer class.

Here, the inner class Can access private members of external classes-

class Outer {
   class Inner {

   }

}
Copy after login

The above is the detailed content of What is the C# equivalent of the friend keyword in C++?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template