I don't understand how this compiles and works perfectly :|
Since when is it possible to change the type of a property (from Nullable<bool>
to bool
and from int
to Nullable<int>
) when overriding it?
public class Program
{
public static void Main(string[] args)
{
var testBase = new BaseClass();
var testDerived = new DerivedClass();
Console.WriteLine("'" + Convert.ToString(testBase.BaseInt) + "'");
Console.WriteLine("'" + Convert.ToString(testDerived.BaseInt) + "'");
Console.WriteLine("'" + Convert.ToString(testBase.BaseBoolNullable) + "'");
Console.WriteLine("'" + Convert.ToString(testDerived.BaseBoolNullable) + "'");
}
}
public class BaseClass
{
public bool? BaseBoolNullable { get; set; }
public int BaseInt { get; set; }
}
public class DerivedClass : BaseClass
{
public new bool BaseBoolNullable { get; set; }
public new int? BaseInt { get; set; }
}
Output:
'0'
''
''
'False'