Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Last active July 10, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/4cee893919a31e6451208d5aae73bc88 to your computer and use it in GitHub Desktop.
Save christiannagel/4cee893919a31e6451208d5aae73bc88 to your computer and use it in GitHub Desktop.
Range struct needed by C# 8 range features
public readonly struct Range
{
public Index Start { get; }
public Index End { get; }
private Range(Index start, Index end)
=> (Start, End) = (start, end);
public static Range Create(Index start, Index end) => new Range(start, end);
public static Range FromStart(Index start) => new Range(start, new Index(0, fromEnd: true));
public static Range ToEnd(Index end) => new Range(new Index(0, fromEnd: false), end);
public static Range All() => new Range(new Index(0, fromEnd: false), new Index(0, fromEnd: true));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment