Working with sets and bags using LINQ
Sets are one of the most fundamental concepts in mathematics. A set is a collection of one or more unique objects. A multiset or bag is a collection of one or more objects that can have duplicates. You might remember being taught about Venn diagrams in school. Common set operations include the intersect or union between sets.
Let's create a console application that will define three arrays of string
values for cohorts of apprentices and then perform some common set and multiset operations on them.
- Create a new console application project named
LinqWithSets
, add it to the workspace for this chapter, and select the project as active for OmniSharp. - Import the following additional namespaces:
using System.Collections.Generic; // for IEnumerable<T> using System.Linq; // for LINQ extension methods
- In
Program
, before theMain
method, add the following method that outputs any sequence ofstring
variables as a comma-separated...