От: | retalik | www.airbandits.com/ | |
Дата: | 19.03.10 06:23 | ||
Оценка: | 3 (1) |
(http://msdn.microsoft.com/en-us/library/79b3xss3(VS.80).aspx)Static members are initialized before the static member is accessed for the first time, and before the static constructor, if any is called.
class Test
{
public static void Main()
{
System.Console.WriteLine(Problem.Message);
}
}
public class Problem
{
public static string Message = InnerInstance.Message;
public class Inner
{
public string Message { get { return "Test"; } }
}
private static readonly Inner _innerInstance = new Inner();
public static Inner InnerInstance { get{ return _innerInstance; } }
}
Unhandled Exception: System.TypeInitializationException: The type initializer for 'Problem' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Problem..cctor()
--- End of inner exception stack trace ---
at Test.Main()