【发布时间】:2011-10-20 00:40:34
【问题描述】:
我有这样的数组
private Type[] _excludeExceptions;
我想搜索一下,发现被搜索的类型存在于数组中。
【问题讨论】:
我有这样的数组
private Type[] _excludeExceptions;
我想搜索一下,发现被搜索的类型存在于数组中。
【问题讨论】:
好吧,用Contains怎么样:
bool x = _excludeExceptions.Contains(typeToFind);
这不适合你吗?
【讨论】:
public bool Excluded(Type t)
{
foreach(var type in _excludeExceptions)
{
if(type.Equals(t))
return true;
}
}
如果 .Net 3.5 或更高版本,您也可以使用 linq:
return _excludeExceptions.Any(type => type.Equals(t));
【讨论】:
bool typexists = _excludeExceptions.Contains(tpyeof(sometype));
【讨论】: