값이 제네릭 기본 클래스의 형식과 관련이 없다면, 그들은 shouldn 제네릭 기본 클래스에 있어야합니다. 그것들은 완전히 별개의 클래스이거나 generic 클래스의 비 제네릭 기본 클래스에 있어야합니다. 정적 변수를 들어, 형식 인수 조합에 따라 다른 정적 변수를 얻을
곰 염두에두고 : 당신이하지 정말이 일반의 T
마다 다른 정적 변수를 원하는 것처럼
using System;
public class GenericType<TFirst, TSecond>
{
// Never use a public mutable field normally, of course.
public static string Foo;
}
public class Test
{
static void Main()
{
// Assign to different combination
GenericType<string,int>.Foo = "string,int";
GenericType<int,Guid>.Foo = "int,Guid";
GenericType<int,int>.Foo = "int,int";
GenericType<string,string>.Foo = "string,string";
// Verify that they really are different variables
Console.WriteLine(GenericType<string,int>.Foo);
Console.WriteLine(GenericType<int,Guid>.Foo);
Console.WriteLine(GenericType<int,int>.Foo);
Console.WriteLine(GenericType<string,string>.Foo);
}
}
소리가 난다 기본 클래스 - 을 일반 기본 클래스에 넣을 수 없습니다.
이미 지적한대로 비 일반 기본 클래스를 사용하는 유일한 방법은 아니지만 '해킹'이 아니라 실제 수행하는 올바른 방법입니다. –