0

Array Split without using LINQ?

I wrote a method that splits a one dimensional string array of x elements into individual one element arrays. The purpose was to see if I could count the characters in each individual element by index in the original string array. To do this I used LINQ methods, but I keep wondering how you would do it with basic Array methods if you decided to. Lines 93 - 106 are the method in question. I keep thinking it must be some mixture of IndexOf and ToString but I’m not sure. Any insight is very appreciated! https://code.sololearn.com/cTs0746Sa73K/?ref=app

9th Jan 2020, 6:00 PM
Josh S
Josh S - avatar
3 Respostas
+ 1
It's a bit erracic what you do in that method. If you only want to know the number of characters in each string, then just use the names[i].Length property. If you want to create a subarray of the names, then declare another array and you can use Array.Copy() method to copy part of the original array. string[] someNames = new string[2]; Array.Copy(names, 1, someNames, 0, 2); This would copy two names from the first array, starting index 1. https://docs.microsoft.com/en-us/dotnet/api/system.array.copy?view=netframework-4.8
9th Jan 2020, 8:26 PM
Tibor Santa
Tibor Santa - avatar
+ 1
I was led to believe in order to find the length of each string in the array, I would have to isolate it on own, by index. It seems Ive gone and over complicated it 😅
10th Jan 2020, 12:29 PM
Josh S
Josh S - avatar
+ 1
Youre the best. The LINQ function was never needed at all.
10th Jan 2020, 12:37 PM
Josh S
Josh S - avatar