Are there special operators in c # for determining whether a number belongs to a set? The analogue in pascal: 2 in [1..4], returns true in this case.
|
2 answers
In C #, there is a type that represents a set. For your case, the analog is HashSet<int> . Check entry is trivial:
var x = new HashSet<int>() { 2, 3, 4 }; Console.WriteLine(x.Contains(2)); // выдаёт True But there are no such convenient set literals, as in Pascal, in C #, the closest analogue [2..4] is
new HashSet<int>(Enumerable.Range(start: 2, count: 3)) There is currently no special support for sets at the syntax level in C #.
|
