Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using C# 8 Ranges with Arrays
var arr = new[] { 1, 4, 8, 11, 19, 31 };
var range = arr[2..5];
ref int elt = ref range[1];
elt = 42;
int copiedelement = range[1];
copiedelement = 11;
Console.WriteLine($"the original element is changed: {arr[3]}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment