-1
public class SampleFile<Toriginal>
{
public SampleFile(File filename,string sname)
{
}
}
如何通過一個值Samplefile
構造?如何將參數傳遞給在C#.NET泛型類的構造函數?
public class SampleFile<Toriginal>
{
public SampleFile(File filename,string sname)
{
}
}
如何通過一個值Samplefile
構造?如何將參數傳遞給在C#.NET泛型類的構造函數?
File
是一個靜態類,你不能把它作爲一個參數。
將其更改爲string
:
public class SampleFile<Toriginal>
{
public SampleFile(string filename,string sname)
{
//Here you can use File as it is static
var lines = File.ReadAllLines(filename);
}
}
然後叫它正常:
var sample = new SampleFile<Type>(@"c:\hi.txt", "bye.txt");
它沒有任何相關的泛型,這不會因爲你的方法聲明靜態參數編譯 – Ofiris