How to read n characters from a text file with TextReader in C#

1 Answer

0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (TextReader reader = File.OpenText("d:\\test.txt"))
            {
                char[] ch_arr = new char[6];

                reader.ReadBlock(ch_arr, 0, 6);

                Console.WriteLine(ch_arr); // Text F
            }
        }
    }
}

/*
run:
   
Text F

*/


answered Mar 12, 2015 by avibootz

Related questions

1 answer 203 views
1 answer 251 views
1 answer 280 views
1 answer 175 views
1 answer 168 views
1 answer 177 views
177 views asked Mar 12, 2015 by avibootz
...