C# - Intersect and Except in Linq form

Something the intersect and except won't be enough for some comparisons. we will have to dig in for some particular type of values like ids, name, etc. Below is an example of this.

Intersect in linq form-

A.Intersect(B) => gives stuff in  both A and B
            var intersect = A.Where(x => B.Select(y => y.Id).Contains(x.Id)).ToList();

Except in linq form-

A.Except(B) => gives stuff in  A and NOT B
            var intersect = A.Where(x => !B.Select(y => y.Id).Contains(x.Id)).ToList();

Comments

  1. awesome! I really appreciate the amazing work you have been doing. and in fact, this article was so amazing that I couldn't stop myself from sharing it with my blog readers.

    I have mentioned you in one of my recent blog posts here:
    click here

    would you mind if I ask you to check it out and share it with your fans and followers?

    If you share it, I'll be highly grateful for your kind act. If not I'll still appreciate your work, no hard feelings.

    Thanks!

    Regards,
    Spiritual Teja
    spiritual information
    click here

    ReplyDelete

Post a Comment

Popular posts from this blog

How To Install LEX and YACC in Linux or Ubuntu

Lex Program To Check The Syntax of For Loop

Listing/Delisting of an article in to an Assortment in SAP SCM Retail