假设我有两种类似的方法:
public List<object> Do<T>(Stream stream)
{
... does cool things
}
public List<object> Do(Type type, Stream stream)
{
T = type // <- what should this be
return Do<T>(Stream);
}
什么代码可以使其按预期运行?
我想这个问题必须在这里重复一些,但我的google-fu找不到。
最佳答案
如果以其他方式进行操作,这很容易:
public List<object> Do<T>(Stream stream)
{
var type = typeof(T);
Do(type, stream);
}
然后,另一种方法将包含非重复逻辑。
关于c# - 创建通用T参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8128629/