Given the C# code below, I expected the private data member _userDataStorage to be initialized immediately. Instead I find that it is not being initialized at all. I put a breakpoint on the initialization statement and it is never hit. This means the DB static property always returns NULL. Do static classes work differently than non-static classes?
public static class UserDataStorageWrapper
{
private static UserDataStorage _userDataStorage = new UserDataStorage();
public static UserDataStorage DB
{
get
{
return _userDataStorage;
}
}
}
I will change the code to check for NULL and initialize _userDataStorage myself for now. But I want be sure about my expectations here.