Could anybody explain why the static property is null?
class Program
{
static void Main(string[] args)
{
string s = Cc.P1; // is null
}
}
public class Cc
: Ca
{
static Cc()
{
P1 = "Test";
}
}
public abstract class Ca
{
public static string P1
{
get;
protected set;
}
}
That because when you write
Cc.P1, you’re actually referring toCa.P1because that’s where it is declared (sinceP1is static, it is not involved in polymorphism). So in spite of appearances, your code isn’t using theCcclass at all, and theCcstatic constructor is not executed.