Created
September 10, 2014 10:28
-
-
Save margusmartsepp/ef74a3ed27c2ad67f05f to your computer and use it in GitHub Desktop.
Changing default value for inherited members
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Class1 | |
| { | |
| internal static int Myvar; | |
| private int _myVar; | |
| public int MyVar1 | |
| { | |
| get{return this.GetType().IsSubclassOf(typeof(Class1)) ? Myvar : _myVar;} | |
| set{_myVar = value;Myvar = value;} | |
| } | |
| } | |
| public class Class2 : Class1 | |
| { | |
| public int MyVar2 { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myC1 = new Class1 { MyVar1 = 10 }; | |
| var myC2 = new Class2 { MyVar2 = 15 }; //myC2.MyVar1 = 10 | |
| var myC3 = new Class1 { MyVar1 = 11 }; //myC2.MyVar1 = 11; myC1.MyVar1 = 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment