For example, there are 2 classes:
class A{ BB; } class B{ string Name; } Is it possible to make it so that class A has the full right to change the value of B, while the user outside can only read it?
Yes, it is. Internal classes have similar functionality. Here is an example:
public class Test { public int X { get; private set; } public class TestMutator { public static void Mutate(Test t) { t.X++; } } } Test test = new Test(); Console.WriteLine(test.X); // 0 Test.TestMutator.Mutate(test); Console.WriteLine(test.X); // 1 This feature is often used, for example, to implement the Iterator pattern. For example, the enumerator List<T> in the Microsoft implementation is defined internally, and has access to the _version private field.
For external classes, there is no such functionality, since access to the “internals” of a class is a violation of encapsulation.
var , business! And let an instance of the inner class create an outer class, for example. - VladDSource: https://ru.stackoverflow.com/questions/805718/
All Articles
internal, which allows you to access a member (method or variable) only from the same assembly. - Alexey Sarovsky