Hello,
I have a problem to add string arrays into the ArrayList.
My data is recorded as: {"1","0","a"}, {"1","1","b"}, ....
I'm going through the "for" loop and trying to store each of these records into the ArrayList, but, after it stores all records, it appears that all elements in the ArrayList are the same!
Here's an example of code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string[] fr;
string[] bd;
ArrayList m;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
fr = new string[5] { "1", "2", "3", "4", "5" };
bd = new string[5] {"a", "b","c", "d", "e"};
m = new ArrayList();
dosomething();
}
private void dosomething()
{
string[] record = new string[3];
for (int i = 0; i < 5; i++)
{
record[0] = "1";
record[1] = fr[i];
record[2] = bd[i];
m.Add(record);
}
}
}
}
All records in m are equal to: {"1","5","e"}. WHY?
Thanks!