Using C# 8 Ranges with Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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