+ 1
Simplify return array of chars
This method creates an array of chars which filled with first chars from alphabet but the return row seems too hard. How is it work? Is there any way to turn this line in a simpler form? static char[] createCharArray(int charArrayLength) { return (from c in new char[charArrayLength] select alphabet[0]).ToArray(); }
1 ответ
+ 1
What language are you using? If its c# you can store alphabet as a List<char> and then use Linq. return alphabet. Take(charArrayLength).AsArray().
If not then you can always write your own functions to do the same thing if you want to tidy up, but sometimes its better to leave a little extra code than having to provide the outer wrapper.