
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is the C# equivalent of C++ friend keyword?
friend in C#
A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.
A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.
C++ equivalent of friend in C#
The closest equivalent is to create a nested class that will access the outer class private members.
Here, the inner class can access the Outer class private members −
class Outer { class Inner { } }
- Related Articles
- PHP equivalent of friend or internal
- Equivalent of Java Super Keyword in C#
- What is the C++ equivalent of sprintf?
- What is Python equivalent of the ! operator?
- What is the equivalent of EXCEPT in MySQL?
- What is the use of "is" keyword in C#?
- What is the Certainty Equivalent Method?
- What are the qualities of a best friend?
- What is equivalent ratio?
- What is the equivalent of SQL “like” in MongoDB?
- What is the equivalent of C# namespace in Java?
- What is the C# Equivalent of SQL Server DataTypes?
- What is Keyword Streaming?
- What is the usage of yield keyword in JavaScript?
- What is the use of ‘new’ keyword in C#?

Advertisements