Неточности стандарта C# или я опять чего-то непонимаю?
От: BokiyIS  
Дата: 12.07.08 22:49
Оценка:
Во время чтения "C# Language Specification Version 3.0" смутила пара моментов:

1) В стандарте написано:

10.3.3 Inheritance
A class inherits the members of its direct base class type. Inheritance means that a class implicitly contains all members of its direct base class type, except for the instance constructors, destructors and static constructors of the base class.


Однако касательно статических перенных это не есть правда, ведь (http://www.rsdn.ru/forum/message/1195767.1.aspx):
Автор: Chupa_Kabra
Дата: 30.05.05

class Program
{
  static void Main(string[] args)
  {
    Console.WriteLine(B._str);
  }
}

class A
{
  public static string _str = "test";
}

class B: A {}


заменится компилятором на:
Console.WriteLine(A._str);


Хотя после прочтения стандарта кажется, что каждый наследуемый тип должен иметь свою статическую переменную _str

2) В стандарте написано:

10.12 Static constructors
...
The execution of a static constructor is triggered by the first of the following events to occur within an application domain:
• An instance of the class type is created.
• Any of the static members of the class type are referenced.


Проверяем:
public class A
{
  public static string str = Init();

  public static void Yell()
  {
    Console.WriteLine(">> Yell");
  }

  private static string Init()
  {
    return ">> Init";
  }

  static A()
  {
  }
}

public class EntryPoint
{
  static void Main()
  {
    A.Yell();
  }
}


Вывод программы:

>> Yell


И никаких ">> Init".
Подскажите пожалуйста, может я где-то что-то не так понял.
inheritance static constructor
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.