2011-08-04 42 views
-1

我有這樣的陣列搜索類型數組

private Type[] _excludeExceptions; 

我想搜索並找到搜索類型​​數組存在。

回答

2

那麼,如何使用Contains

bool x = _excludeExceptions.Contains(typeToFind); 

難道不是爲你工作?

1
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)); 
1
bool typexists = _excludeExceptions.Contains(tpyeof(sometype));