【发布时间】:2011-04-18 13:27:28
【问题描述】:
可能重复:
C# how do I compare two objects if they are of same type?
我有一个通用函数,
class Something {
public int found;
public Something() {
this.found = true;
}
}
List<Something> something;
public int countFound<T>(List<T> Organisms)
{
if (typeof(T) == typeof(Something))
{
foreach (T organism in Organisms)
{
// here i want to check something like organism.found == true how do i do it?
}
}
return 0;
}
提前感谢所有帮助!
【问题讨论】:
-
我认为标题具有误导性,问题是如何处理泛型类型方法来访问某些属性。
-
让我说,如果你在泛型类型参数上进行分支,你所做的可能不是很通用。
标签: c# generics types comparison compare