I read a text file and stored in a List<string> and I read first word in each line and assign it to a string array(string[]) but I got an error
the text file like this:
OH, xxx, xxx, x
PA, xxx, xxx, x
WA, xxx, xxx, x
I want to put OH, PA, WA etc into string[];
private string[] GetCodes(string file)
{
string[] Code = null;
List<string> list = File.ReadAllLines(filePath).ToList<string>( );
for(int i = 0; i < list.Count - 1; i++)
{
Code[i] = list[i].Split(',')[0];//here throws an Object reference not set to an instance of an object exception.
}
return Code;
}
Any help is appreciated;
Go to the complete details ...