如何将参数传递给 c#.net 中的泛型类构造函数
本文关键字:泛型类 构造函数 net 参数传递 | 更新日期: 2023-09-27 18:32:38
public class SampleFile<Toriginal>
{
public SampleFile(File filename,string sname)
{
}
}
如何将值传递给构造函数Samplefile
?
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");