I have a string array that has a list of values like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
I am trying only to get the first ten so my output looks like this and store it another string array.
1
2
3
4
5
6
7
8
9
10
it seems really easy i just can't figure it out
for (int i=0; i<Math.Min(10, array.Length); i++)
Console.WriteLine(array[i]);
OR
foreach (int i in array.Take(10))
Console.WriteLine(array[i]);
EDIT: Based on your comment that you want it in a string array. Here is what you have to do
string[] numbers = array.Take(10).Select(i=>i.ToString()).ToArray();
You can use Linq. You need to include the reference and the using directive:
using System.Linq;
theStringsArray.Take(10).ToArray();
You can use
Array.Copy(SourceArray, DestinationArray, 10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With