C# slices support
Support for slices.
var list = new List<int>() { 1, 3, 3, 7, 8, 9 };
var slice = list[0..3];
4 comments
-
Robert Einhorn
commented
-
Qwertie
commented
Judah, using Linq.Enumerable for slices would be incredibly slow. It's better to write your own ListSlice<T> class and extension method(s) to create slices from IList<T>. I have done just that in my own toolbox.
If .NET had supported array slices as a native feature, like Go does, they could have been used instead of arrays in most of the BCL and parts of the BCL would have been simpler. There are potential performance advantages of array slices, too: http://loyc-etc.blogspot.com/2010/05/new-features-net-framework-should-have.html
Even better, read-only array slices would have allowed Reflection to return metadata faster (instead, Reflection creates new arrays for every metadata request). It's too late now I guess...
-
Robert Einhorn
commented
I think the "slice support" would be simpler and faster running then the same with LINQ.
-
Judah
commented
Don't care for this. You can already do this with LINQ, via the .Take and .Skip methods, e.g. list.Take(3)