1
我想重載一個構造函數,除了默認的構造函數,它只會被調用類型int。我得到的最接近的是this。重載通用類的構造函數,基於類型
如果不可能,爲什麼?
class Program
{
static void Main()
{
//default construcotr get called
var OGenerics_string = new Generics<string>();
//how to make a different construcotr for type int
var OGenerics_int = new Generics<int>();
}
class Generics<T>
{
public Generics()
{
}
// create a constructor which will get called only for int
}
}
你不能真正做到這一點,這是一個有點代碼味道的了。 – DavidG