C#에서 첫 번째 호출 유형이 발견되면 CLR은이 유형을 찾아서 유형 객체 포인터, 동기화 블록 인덱서, 정적 필드, 메소드 테이블을 포함하는이 유형의 객체 유형을 만듭니다 이가 그 후 다시제네릭 클래스의 정적 제네릭 필드
GenericTypesClass<string, string>.firstField = "firstField";
GenericTypesClass<string, string>.secondField = "secondField";
및
GenericTypesClass<int, int>.firstField = 1;
GenericTypesClass<int, int>.secondField = 2;
필드에 대한 (책 'C#을 통해 CLR'의 4 장에 대한 추가 정보를 원하시면) .Okay, 일부 제네릭 형식은 정적 일반적인 fields.We 설정 값이 힙은 두 개의 다른 객체 유형을 만들었는지, 아니면 만들지 않았습니까?
여기더 examles :
일반적인 유형이 제 매개 변수로 값 유형으로 구성된다class Simple
{
}
class GenericTypesClass<Type1,Type2>
{
public static Type1 firstField;
public static Type2 secondField;
}
class Program
{
static void Main(string[] args)
{
//first call GenericTypesClass, create object-type
Type type = typeof (GenericTypesClass<,>);
//create new object-type GenericTypesClass<string, string> on heap
//object-type contains type-object pointer,sync-block indexer,static fields,methods table(from Jeffrey Richter : Clr Via C#(chapter 4))
GenericTypesClass<string, string>.firstField = "firstField";
GenericTypesClass<string, string>.secondField = "secondField";
//Ok, this will create another object-type?
GenericTypesClass<int, int>.firstField = 1;
GenericTypesClass<int, int>.secondField = 2;
//and another object-type?
GenericTypesClass<Simple,Simple>.firstField = new Simple();
GenericTypesClass<Simple, Simple>.secondField = new Simple();
}
}