Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# read file by line

using (var file = new StreamReader(fileName)) {
	string line;
	while((line = file.ReadLine()) != null)  
	{  
		System.Console.WriteLine(line);
	}  
}
Comment

c# read file line by line

using System;
using System.IO;
 
public class Example
{
    public static void Main()
    {
        string fileName = @"C:examplepath.txt";
 
        using (StreamReader streamReader = File.OpenText(fileName))
        {
            string text = streamReader.ReadToEnd();
            string[] lines = text.Split(Environment.NewLine);
 
            foreach (string line in lines) {
                Console.WriteLine(line);
            }
        }
    }
}
Comment

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();
   }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: top level statements c# 
Csharp :: datetime in specific format c# 
Csharp :: wpf resource dictionary 
Csharp :: c# webclient post file 
Csharp :: generate random dark colors programatically in android 
Csharp :: list to array c# 
Csharp :: get all components of type unity 
Csharp :: how to deserialize string array in c# 
Csharp :: c# file read 
Csharp :: c# use api rest 
Csharp :: c# merge two xml files 
Csharp :: c# file watcher 
Csharp :: print an array in c# 
Csharp :: how to append something to a string in c# 
Csharp :: vb.net add row to datagridview programmatically 
Csharp :: c# mongodb get all documents 
Csharp :: upload file using httpwebrequest c# 
Csharp :: addd to array c# 
Csharp :: pyautopgui wrros on big sur 
Csharp :: remove force unity 
Csharp :: c# xml get root attributes 
Csharp :: compact in laravrl 
Csharp :: unity get pivot position 
Csharp :: unity gameobject find inactive 
Csharp :: which game engine is best 
Csharp :: c# add key value pair to dictionary 
Csharp :: singleton design pattern c# volatile 
Csharp :: new datetime c# 
Csharp :: expansion tile 
Csharp :: unity c# move transform 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =