hi everyone I'm new to c# and working with file currently I need to read some string from the file but not the whole file so what functions can I use to read the file string by string ?

Ok I want to read a line and compare it with some string is there's any function that read a line from text file ?

System.IO.TextReader tr = new System.IO.StreamReader("c:\\myFile.txt");
if (tr.Peek() > -1)
{
    string line=tr.ReadLine();
}
tr.Close();
//Declare and init variable of text reader and specify the file full path
System.IO.TextReader tr = new System.IO.StreamReader("c:\\myFile.txt");
//check if file has data (not empty)
//Peek() get the next char and return -1 if EOF
if (tr.Peek() > -1)
{    
//Read Line
string line=tr.ReadLine();
}
//Close the file
tr.Close();

ok thanks a lot this code will read a single line at each iteration till the end of the file
??

and I have another question little bit far from my first question , I used to program in c++ and I recently move to c# but I have never programmed windows application , so if I declared any class does it have to be inherited from Form ??

Edited 5 Years Ago by alaa sam: wrong spilling

so this means that I can create any classes as in console applications and use them ,

ok so I need to use forms for input and output and the rest is as in console applications ??

This question has already been answered. Start a new discussion instead.