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

read line c#

Console.ReadLine();
//will read what was input to the command
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 :: unity get all children 
Csharp :: how to instantiate a gameobject 
Csharp :: c# web api return image file 
Csharp :: asp.net data annotations double 
Csharp :: distinct prime factors count of a number 
Csharp :: .net c# print object 
Csharp :: create instance of class given class name string c# 
Csharp :: xamarin forms open new page on button click 
Csharp :: yanderedev 
Csharp :: failed to read the request form. missing content-type boundary .net core 
Csharp :: redirect to another controller page in asp.net core 
Csharp :: c list add element 
Csharp :: c# is in array 
Csharp :: mapping dictionary to object c# 
Csharp :: make http request c# 
Csharp :: c# loop through list of objects 
Csharp :: get out of foreach statement c# 
Csharp :: get width of image unity 
Csharp :: c# for loop next iteration 
Csharp :: turn list of string to csv c# 
Csharp :: getmousebuttondown unity 
Csharp :: get text unity 
Csharp :: c# dictionary values to list 
Csharp :: fluent assertions exception 
Csharp :: c# execute shell command 
Csharp :: list search c# 
Csharp :: lcm of list of number 
Csharp :: font dialog c# code 
Csharp :: how to get keyboard input in unity 
Csharp :: an existing connection was forcibly closed by the remote host. .net core 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =