C# 搜索类型数组
我有这样的阵列C# 搜索类型数组,c#,arrays,types,C#,Arrays,Types,我有这样的阵列 private Type[] _excludeExceptions; 我想搜索它,并找到数组中存在的已搜索类型。那么,使用Contains如何: bool x = _excludeExceptions.Contains(typeToFind); 这对你不管用吗 public bool Excluded(Type t) { foreach(var type in _excludeExceptions) { if(type.Equals(t)) ret
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或更高版本:
return _excludeExceptions.Any(type => type.Equals(t));
bool typexists = _excludeExceptions.Contains(tpyeof(sometype));