9 public struct Range<T> where T : notnull, IComparable<T>
11 private T start;
private T end;
18 VerifyStartLessThanEnd();
28 VerifyEndGreaterThanStart();
33 => start.CompareTo(v) <= 0 && end.CompareTo(v) >= 0;
35 private void VerifyStartLessThanEnd()
37 if (start.CompareTo(end) > 0) {
throw new InvalidOperationException($
"Range<{typeof(T).Name}>.Start set to a value greater than End ({start} > {end})"); }
40 private void VerifyEndGreaterThanStart()
42 if (end.CompareTo(start) < 0) {
throw new InvalidOperationException($
"Range<{typeof(T).Name}>.End set to a value less than Start ({end} < {start})"); }
47 this.start = start; this.end = end;
48 VerifyEndGreaterThanStart();
An inclusive range, i.e. [Start, End] where Start <= End
readonly bool Contains(in T v)