public abstract class EventSystemBase<T, K> : IAutoEvent
where T : Event
where K : IAutoEvent, new()
{
public static T Instance { get { return EventSystem.Events.OfType<T>().FirstOrDefault(); } }
public static IAutoEvent AutoEventInstance { get { return new K(); } }
static EventSystemBase()
{
EventBot.Register(new EventBotEntry(Instance.Name, AutoEventInstance));
}
[...]
}
我不太理解这个是如何编译的。
- 静态构造函数什么时候运行?
- 为什么可以在静态成员中使用泛型类型?
- 它应该如何知道要应用哪些类型?
class Foo<T> {public static int x = 0;}
Foo<int>.x = 10;
Console.WriteLine(Foo<string>.x) //仍然是零
- Mark Cidade