我需要在中点将一个不确定大小的数组拆分成两个独立的数组.
使用ToArray()从字符串列表生成数组.
public void AddToList ()
{
bool loop = true;
string a = "";
Console.WriteLine("Enter a string value and press enter to add it to the list");
while (loop == true)
{
a = Console.ReadLine();
if (a != "")
{
mylist.Add(a);
}
else
{
loop = false;
}
}
}
public void ReturnList()
{
string x = "";
foreach (string number in mylist)
{
x = x + number + " ";
}
Console.WriteLine(x);
Console.ReadLine();
}
}
class SplitList …Run Code Online (Sandbox Code Playgroud)