Edit: Ho provato il metodo Take/Skip ma ottengo il seguente errore:Dividere un array in 2 array C#
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string>' to
'string[]'. An explicit conversion exists (are you missing a cast?)
non so quello che sto facendo male perché ho copiato Saeed di codice.
Ho un array di stringhe (contenente ovunque da 20 a 300 elementi) e voglio dividerlo in 2 array separati, dal centro del primo.
So come posso farlo utilizzando un ciclo for, ma mi piacerebbe sapere se c'era un modo più veloce/migliore di farlo. Ho anche bisogno di essere in grado di dividere correttamente una matrice anche se ha un numero dispari di elementi, ad esempio:
string[] words = {"apple", "orange", "banana", "pear", "lemon"};
string[] firstarray, secondarray;
SplitArray(words, out firstarray, out secondarray); // Or some other function
// firstarray has the first 3 of the items from words, 'apple', 'orange' and 'banana'
// secondarray has the other 2, 'pear' and 'lemon'
Al fine di risolvere il problema fuso aggiungere '.ToArray()' dopo il prendere e saltare metodi –