Answers for "how to read particular line of file in c#"

C#
6

c# read file line by line

int counter = 0;  
string line;  
  
// Read the file and display it line by line.  
System.IO.StreamReader file =
    new System.IO.StreamReader(@"c:\test.txt");  
while((line = file.ReadLine()) != null)  
{  
    System.Console.WriteLine(line);  
    counter++;  
}  
  
file.Close();  
System.Console.WriteLine("There were {0} lines.", counter);  
// Suspend the screen.  
System.Console.ReadLine();
Posted by: Guest on February-11-2021
0

how to read particular line of file in c#

string GetLine(string fileName, int line)
{
   using (var sr = new StreamReader(fileName)) {
       for (int i = 1; i < line; i++)
          sr.ReadLine();
       return sr.ReadLine();
   }
}
Posted by: Guest on March-16-2021

Code answers related to "how to read particular line of file in c#"

C# Answers by Framework

Browse Popular Code Answers by Language