値がジェネリック基本クラスの型とは何の関係もない場合、それらはジェネリック基本クラスにあるべきではありません。それらは、完全に別のクラスにあるか、ジェネリック クラスの非ジェネリック基本クラスにある必要があります。
静的変数の場合、型引数の組み合わせごとに異なる静的変数が得られることに注意してください。
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);
}
}
ジェネリック基本クラスごとに異なる静的変数が本当に必要ないように思えます-そのため、ジェネリック基本クラスにそれをT
含めることはできません。