Skip to content

Instantly share code, notes, and snippets.

@margusmartsepp
Created September 10, 2014 10:28
Show Gist options
  • Select an option

  • Save margusmartsepp/ef74a3ed27c2ad67f05f to your computer and use it in GitHub Desktop.

Select an option

Save margusmartsepp/ef74a3ed27c2ad67f05f to your computer and use it in GitHub Desktop.
Changing default value for inherited members
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; }
}
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