开发者

Search Type array

开发者 https://www.devze.com 2023-03-26 01:36 出处:网络
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:

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

精彩评论

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