Why can a definition of the next class access private data of another object of the same class?

Why is the definition of the next class can access the private data elements other._nameand other._idfrom another object of the same class?

Thank.

public class MyData : IEquatable<MyData>
{

    private long _id;
    private string _name;

    public bool Equals(MyData other)
    {
        bool ret =
            string.Equals(_name, other._name) &&
            long.Equals(_id, other._id);

        return ret;
    }

}
+4
source share
1 answer

If you look at the documentation for private, you will see the following:

The private keyword is the membership access modifier. Private access is the least permissible level of access. Private members are only accessible inside the body of the class or structure in which they are declared, as in this example:

LIke , . , , , , .

+3

Source: https://habr.com/ru/post/1668696/


All Articles