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

前端 未结 7 1160
轻奢々
轻奢々 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<TResult>(this IEnumerable source)
    {
        Type type = typeof(Type);
    
        foreach (var item in source)
        {
           if (type != item.GetType())
            {
                yield return item;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题