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();
}
}
whileloop right above that is exiting only afterreadis null, so of courseread.ToCharArray()will give the exception.read.ToCharArray()to achieve?while (read != null)For example, step 1: Read the entire file and print it out. Step 2 I want to access the file again; I'll have to restart at the beginning of the file.