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

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

PHPz
PHPzforward
2023-09-15 10:53:02739browse

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 {

   }

}

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Access modifiers in C#Next article:Access modifiers in C#