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 214 views
1 answer 263 views
1 answer 290 views
1 answer 184 views
1 answer 181 views
1 answer 196 views
196 views asked Mar 12, 2015 by avibootz
...