Operators

Joins

var leftOuterJoin = 
    from l in leftCollection
    join r in rightCollection on l.Key equals r.Key into joined
    from r in joined.DefaultIfEmpty()
    select new { l, r };

Quantifier Operations

Method NameDescription

All

Determines whether all the elements in a sequence satisfy a condition.

Any

Determines whether any elements in a sequence satisfy a condition.

Contains

Determines whether a sequence contains a specified element.

Set Operations

Method namesDescription

Distinct or DistinctBy

Removes duplicate values from a collection.

Except or ExceptBy

Returns the set difference, which means the elements of one collection that do not appear in a second collection.

Intersect or IntersectBy

Returns the set intersection, which means elements that appear in each of two collections.

Union or UnionBy

Returns the set union, which means unique elements that appear in either of two collections.

string[] planets = { "Mercury", "Venus", "Venus", "Earth", "Mars", "Earth" };
string[] planets2 = { "Mercury", "Earth", "Mars", "Jupiter" };

IEnumerable<string> distinctMethod = from planet in planets.Distinct()
                            select planet;
IEnumerable<string> exceptMethod = from planet in planets1.Except(planets2)
                            select planet;
IEnumerable<string> exceptMethod = from planet in planets1.Intersect(planets2)
                            select planet;
IEnumerable<string> exceptMethod = from planet in planets1.Union(planets2)
                            select planet;
                            
foreach (var str in distinctMethod)
    Console.Write(str + " ");

/* Distinct() Output : Mercury Venus Earth Mars */
/* Except() Output : Venus */
/* Intersect() Output : Mercury Earth Mars */
/* Union() Output : Mercury Venus Earth Mars Jupiter*/

Last updated