i have numbers that user enter in textBox3 and i converted them to an array nums now i want to put half of them in arraylist A and half of them in arraylist B how can i do that?thanks
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();
edited:
thanks,i tested your answers but output of all of your codes are system.collection.generic[system.int32],whats the problem?thanks
for example i tested this that ArsenMkrt wrote:
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());
}
It’s not recommended using array list because of boxing issues so use lists:
first list contains length/2 to length and second list contains first item to length / 2
Edit: See 101 linq sample for interducing to linq.
Edit: for showing the items in list should traverse list, list.ToString() returns type of list See MSDN ToString not items, so you should override it and use your specific list or do:
Or
Or