How can I implement NotOfType in LINQ that has a nice calling syntax?

前端 未结 7 1184
轻奢々
轻奢々 2020-12-11 00:24

I\'m trying to come up with an implementation for NotOfType, which has a readable call syntax. NotOfType should be the complement to OfType&l

7条回答
  •  爱一瞬间的悲伤
    2020-12-11 01:09

    You might consider this

    public static IEnumerable NotOfType(this IEnumerable source)
    {
        Type type = typeof(Type);
    
        foreach (var item in source)
        {
           if (type != item.GetType())
            {
                yield return item;
            }
        }
    }
    

提交回复
热议问题