我有一个类
我收到了这个编译器错误:
public class A<T>
{
public static string B(T obj)
{
return TransformThisObjectToAString(obj);
}
}
上面的字符串仅仅是举例说明。我可以在已知/指定的类型上这样轻松调用静态函数:
string s= A<KnownType>.B(objectOfKnownType);
如果我不知道T的值,而是有一个类型为Type的变量来保存类型,我该如何进行调用呢?如果我这样做:
Type t= typeof(string);
string s= A<t>.B(someStringObject);
我收到了这个编译器错误:
Cannot implicitly convert type 't' to 'object'