Saturday, 7 September 2013

NullReference Exception in converting string to Char array

NullReference Exception in converting string to Char array

It is showing Null Reference Exception on line "char[] myChar =
read.ToCharArray();". I am unable to figure out. Please help
class Program
{
static void Main(string[] args)
{
StreamReader myReader = new StreamReader("TextFile1.txt");
string read = "";
while (read != null)
{
read = myReader.ReadLine();
Console.WriteLine(read);
}
char[] myChar = read.ToCharArray();
for (int i = 0; i < myChar.Length; i++)
{
Console.WriteLine(myChar[i]);
}
Console.WriteLine(read);
myReader.Close();
Console.ReadKey();
}
}
}

No comments:

Post a Comment