What is the equivalent of a \'friend\' keyword in C Sharp?
How do I use the \'internal\' keyword?
I have read that \'internal\' keyword is a replacement for \'fr
You can use the keyword access modifier internal to declare a type or type member as accessible to code in the same assembly only.
You can use the InternalsVisibleToAttribute class defined in System.Rutime.CompilerServices to declare a type as accessible to code in the same assembly or a specified assembly only.
You use the first as you use any other access modifier such as private
. To wit:
internal class MyClass {
...
}
You use the second as follows:
[assembly:InternalsVisibleTo("MyFriendAssembly", PublicKey="...")]
internal class MyVisibleClass {
...
}
Both of these can rightly be considered the equivalent of friend
in C#.
Methods that are protected are already available to derived classes.