c# list slice

102

c# list slice -

// only available in .NET Core 3.0   :/

var result1 = myList[2..5]; // end (5) is exclusive
var result2 = myList[1..^0]; // from index 1 to the end 
var result3 = myList[0..3]; // end (3) exclusive

c# list slice -

// list[2:4]
var result1 = myList.Skip(2).Take(2);
// list[1:]
var result2 = myList.Skip(1);
// list[:3]
var result3 = myList.Take(3);
// list[:3] + list[4:]
var result4 = myList.Take(3).Concat(myList.Skip(4));

Comments

Submit
0 Comments