我有一个通用函数,我想知道如何编写。
List<Something> something;
public int countItems<T>(List<T> Items)
{
// Here I would like to compare the type of "Items" with the type of "something" to see if they are compatible. How do I do it?
return 0;
}
你的意思是:
if(typeof(T) == typeof(Something)) {...}
?
请注意,泛型很大程度上依赖于 T (并且行为不同)可能意味着您尝试做的事情实际上并不是很generic...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)