I have a public static class that has a number of static methods and static readonly fields.
public static class Global
{
...
// Config is a static method in Global.
public static readonly string FirebaseAuthDomain = Config("FirebaseAuthDomain");
private static readonly string ResourceNameFormat = "{0}.{1}";
...
}
I get a NullReferenceException
when I access ResourceNameFormat
. However, if I move the declaration of ResourceNameFormat
before FirebaseAuthDomain
as shown below, it works fine.
public static class Global
{
...
private static readonly string ResourceNameFormat = "{0}.{1}";
// Config is a static method in Global.
public static readonly string FirebaseAuthDomain = Config("FirebaseAuthDomain");
...
}
It looks like the call to Config()
has something to do with this behavior, but I can't tell why. What is the difference between these two code snippets?