I am trying to use c# Range features with List.
What am I missing to make it work?
- int[] arrayTest = new int[] {1,2,3,4,5 };
- int[] arrayRange = arrayTest[1..^2]; // Works!
- List<int> listTest = new List<int>() {1,2,3,4,5 };
- var listRange = listTest[1..^2]; // does not work.
Thanks!
Pankajkumar PatelPosted Jan 28, 2020, 11:26 AM
“listTest[1..2]” cannot convert from 'System.Range' to 'int'. Hence, you can use it like below using “GetRange”:
For more details, refer following:
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/ranges-indexes#type-support-for-indices-and-ranges
Siddharth GajbhiyePosted Jan 28, 2020, 11:24 AM