这是函数的签名:
public static T[] Shuffle<T>(T[] array)
在函数内部,我想检查类型:
var t = T.GetType();
但我收到此错误:
'T' is a type parameter, which is not valid in the given context
知道为什么我会出错以及如何获得 T 类型吗?
您可以使用typeof
获取泛型参数的类型:typeof(T)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句