there is an array in c#
string[] arr = new string[] {"1","A","D","3","5","AF","34","TU","E","OP","4"};
so how can i get elements from middle of this array like below
string[] fromArr = new string[5];
fromArr = {"D","3","5","AF","34"};
Do u know any method or any way to do that?
The simplest way is to use LINQ2Objects
The most performant way would be to use
Array.Copy, but that code would be much more cumbersome to write and you need to figure that out yourself, including handling all edge cases when the arrays are not long enough etc.But if you will use the result just a few times you don’t need to copy it back to an array, you can just use the lazy evaluation feature of LINQ2SQL
then you can use
fromArrin a loop or whatever without even copying the data in the first place.When I think about it you may have the option to use
ArraySegment<string>too instead of copying to new arrays.But for the readability and simplicity, stick with the LINQ version unless you have a real reason to use another alternative.