Search Type array
I have such array
private Type[] _excludeExceptions;
I would like to search it and 开发者_如何学Gofind is searched type exist in array.
Well, how about using Contains
:
bool x = _excludeExceptions.Contains(typeToFind);
Does that not work for you?
public bool Excluded(Type t)
{
foreach(var type in _excludeExceptions)
{
if(type.Equals(t))
return true;
}
}
You could also use linq if .Net 3.5 or above:
return _excludeExceptions.Any(type => type.Equals(t));
bool typexists = _excludeExceptions.Contains(tpyeof(sometype));
精彩评论