class StaticConstructors
{
class Outer<T>
{
public class Inner<U, V>
{
static Inner()
{
Console.WriteLine("Outer<{0}>.Inner<{1},{2}>",
typeof(T).Name,
typeof(U).Name,
typeof(V).Name);
}
public static void DummyMethod()
{
}
}
}
static void Main()
{
Outer<int>.Inner<string, DateTime>.DummyMethod();
Outer<string>.Inner<int, int>.DummyMethod();
Outer<object>.Inner<string, object>.DummyMethod();
Outer<string>.Inner<string, object>.DummyMethod();
Outer<object>.Inner<object, string>.DummyMethod();
深入理解 c# 第三章 嵌套泛型类型的静态构造函数
最新推荐文章于 2022-01-29 12:18:00 发布
本文探讨了在C#中,当调用包含嵌套泛型类型的DummyMethod()时,如何触发不同封闭类型的初始化。每个不同的类型参数列表被视为独立的封闭类型,如:Outer<Int32>.Inner<String,DateTime>,Outer<String>.Inner<Int32,Int32>等。这揭示了C#中泛型和静态构造函数的交互机制。"
132647598,18158630,C#编程:创建楼梯图案,"['C#', '开发语言']
摘要由CSDN通过智能技术生成