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!

Siddharth GajbhiyeRank #376 · 6.7K reputationPosted Jan 28, 2020, 6:24 AM EST
Pankajkumar PatelRank #181 · 13.4K reputationPosted Jan 28, 2020, 6:26 AM EST
“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