我有一个通用函数,我想知道如何编写。如何确定两个对象的类型是否兼容?
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;
}
这真的取决于你的比较方法。什么时候和Items一样? – RoflcoptrException 2011-04-18 13:08:17
'var tAsSomething = Items [0] as Something;如果(tAsSomething!= null)...'是我最好的猜测,如果我理解正确。 – 2011-04-18 13:10:04
XY问题的阴影。第一条评论似乎是从字面上看原始问题标题的方式,所以我将标题改为实际意义。 – 2017-10-22 00:08:12