V
V
Vladimir Malkov2018-06-07 09:51:57
C++ / C#
Vladimir Malkov, 2018-06-07 09:51:57

How do private properties work in C#?

There is this code:

class SomeClass
        {
            private bool BoolTest = true;

            public void SomeFunc()
            {
                SomeClass sc = new SomeClass();
                sc.BoolTest = false; // почему-то доступное свойство
            }
        }

        class AccessTester
        {
            public void TestPrivate()
            {
                SomeClass sc = new SomeClass();
                //sc.boolTest = false; конечно недоступное свойство
            }
        }

Please explain why a private property of the sc object is available in SomeFunc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
heartdevil, 2018-06-07
@MalkovVladimir73

The property can also be available for nested classes of the same type.
Tyts

Nested types in the same body can also access those private members.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question