How to use List with c# 8 Range?

Jan 27 2020 3:04 PM
Hello,

I am trying to use c# Range features with List.
What am I missing to make it work?

  1. int[] arrayTest = new int[] {1,2,3,4,5 };  
  2. int[] arrayRange = arrayTest[1..^2]; // Works!
  3.   
  4. List<int> listTest = new List<int>() {1,2,3,4,5 };  
  5. var listRange = listTest[1..^2];  // does not work.
 
Thanks!

Answers (2)