开发者

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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜