Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Readable C# equivalent of Python slice operation

What is the C# equivalent of Python slice operations?

my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] result1 = my_list[2:4] result2 = my_list[1:] result3 = my_list[:3] result4 = my_list[:3] + my_list[4:] 

Some of it is covered here, but it is ugly and doesn't address all the uses of slicing to the point of it not obviously answering the question.

like image 573
LJNielsenDk Avatar asked Dec 19 '13 10:12

LJNielsenDk


People also ask

Is C language readable?

The C program is the human-readable form, while the executable that comes out of the compiler is the machine-readable and executable form. What this means is that to write and run a C program, you must have access to a C compiler.

What is a readable code?

Readable code is simply code that clearly communicates its intent to the reader. Most likely, the code we write will be read by other developers, who will either want to understand or modify the way our code works. They may need to test the code, fix a problem, or add a new feature.

Does Microsoft still use C?

To overcome such issues, Microsoft developers recently announced to use the Rust programming language instead of C and C++ to write and code the components of Windows.


1 Answers

The closest is really LINQ .Skip() and .Take()

Example:

var result1 = myList.Skip(2).Take(2); var result2 = myList.Skip(1); var result3 = myList.Take(3); var result4 = myList.Take(3).Concat(myList.Skip(4)); 
like image 137
Ben Avatar answered Sep 21 '22 06:09

Ben