我同意您的要求聽起來很奇怪,應該用不同的方法解決。然而,這會做你想要什麼:
public T[][] Bloop<T>(T[] items)
{
if (items == null) throw new ArgumentNullException("items");
if (items.Length == 1) return new T[][] { items, new T[] { } };
int firstLength = (int) Math.Ceiling((double)items.Length/2);
T[] firstPart = new T[firstLength];
Array.Copy(items, 0, firstPart, 0, firstLength);
int secondLength = (int)Math.Floor((double)items.Length/2);
T[] secondPart = new T[secondLength];
Array.Copy(items, firstLength, secondPart, 0, secondLength);
return new T[][] { firstPart, secondPart };
}
你的樣品:
string[] str= { "toto", "the", "moto", "my", "friend","12","13","14","99","88"};
string[][] result = Bloop(str);
如果需要第二個數組int[]
可以使用下列內容:
int[] ints = Array.ConvertAll(result[1], int.Parse);
下一步:您向我們展示您嘗試過的方法。 – Noctis
http://pastebin.com/DHPRuDTu – N3wbie