Protected variable unity

Code examples

1
0

protected variable unity

 public class ClassA
 {
     private string text1;
     protected string text2;
     public ClassA()
     {
         text1 = "aaa"; // ok
         text2 = "bbb"; // ok
     }
 }
 public class ClassB : ClassA
 {
     public ClassB()
     {
         text1 = "aaa"; // compile error - you can't access text1, because it is visible only in scope of ClassA
         text2 = "bbb"; // ok - text2 is declared as protected in ClassA, so it is accessible in ClassA and all the classes derived from ClassA
     }
 }

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................