【发布时间】:2010-12-28 08:42:30
【问题描述】:
我有用户在 textBox3 中输入的数字,我将它们转换为数组 nums 现在我想将其中的一半放在 arraylist A 中,将一半放在 arraylist B 中我该怎么做?谢谢
string[] source = textBox3.Text.Split(',');
int[] nums = new int[source.Length];
for (int i = 0; i < source.Length; i++)
{
nums[i] = Convert.ToInt32(source[i]);
}
ArrayList A = new ArrayList();
ArrayList B = new ArrayList();
编辑:
谢谢,我测试了你的答案,但你所有代码的输出都是 system.collection.generic[system.int32],有什么问题?谢谢
例如,我测试了 ArsenMkrt 写的这个:
private void button1_Click(object sender, EventArgs e)
{
string[] source = textBox3.Text.Split(',');
int[] nums = new int[source.Length];
List<int> A = nums.Take(source.Length/2).ToList();
List<int> B = nums.Skip(source.Length/2).ToList();
MessageBox.Show(B.ToString());
}
【问题讨论】:
-
它应该是 system.collection.generic[system.int32] 因为我们创建通用列表,如果你想要 ArrayList,请尝试我的第一个版本的答案,或者使用 .ToArray() 期望 .ToList( ) 获取数组
标签: c# winforms arrays arraylist mergesort