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

read all lines from txt c#

string[] lines_in_file = File.ReadAllLines(@"C:myfilepathfile.txt");
Comment

c# read all lines from filestream

public IEnumerable<string> ReadLines(Func<Stream> streamProvider,
                                     Encoding encoding)
{
    using (var stream = streamProvider())
    using (var reader = new StreamReader(stream, encoding))
    {
        string line;
        while ((line = reader.ReadLine()) != null)
        {
            yield return line;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to compare datetime in c# 
Csharp :: c# how to crete array 
Csharp :: ef core include 
Csharp :: c# how to print 
Csharp :: c# clear an array 
Csharp :: bsod screen c# 
Csharp :: ray casting unity 
Csharp :: c# xml get root attributes 
Csharp :: c# backup sql 
Csharp :: c# next level script 
Csharp :: set current date to textbox in asp.net 
Csharp :: c# online compiler 
Csharp :: c# get all classes derived from type 
Csharp :: c# yield keyword 
Csharp :: unity draw ray from one object to another 
Csharp :: unity switch to scene and transfer data 
Csharp :: how to generate a random number in c# 
Csharp :: Metadata publishing for this service is currently disabled 
Csharp :: how to uncheck a radio button in c# 
Csharp :: c# winscp upload file 
Csharp :: c# bool to int 
Csharp :: add list to list c# 
Csharp :: c# get string in parentheses 
Csharp :: c# destroy function...unity 
Csharp :: preprocessors 
Csharp :: select range in list c# 
Csharp :: how to add event function from code in wpf 
Csharp :: c# find comma in text and remove 
Csharp :: c# merge two lists as queryable 
Csharp :: translate int to string with x 0 before c# 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =