the problem in the cacArray list
?all values of the list take the last value entered and i don't know y
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;//4
namespace ConsoleApplication1
{
class charAndCode
{
private string ch;
private string code;//10
public void setCAC(string[] strArray)
{
ch = strArray[0];
code = strArray[1];
}
public void getCAC()
{
Console.WriteLine(ch);
Console.WriteLine(code);//20
}
}
class Program
{
static void Main(string[] args)//25
{
StreamReader sr = new StreamReader("H:\\sara.txt");
string lineString;
charAndCode cac = new charAndCode();
List<charAndCode> cacArray = new List<charAndCode>(10);//30
do
{
lineString = sr.ReadLine();
string[] array = lineString.Split(' ');//35
cac.setCAC(array);
cacArray.Add(cac);
} while (lineString != "c c");
cacArray[2].getCAC();
}//40
}
}