using System;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
        FileStream f;
        char ch;
        try
        {
            f = new FileStream("abc.dat", FileMode.Create);
        }
        catch (IOException exc)
        {
            Console.WriteLine(exc.Message);
            return;
        }
        for (int i = 0; i < 26; i++)
        {
            try
            {
                f.WriteByte((byte)('A' + i));
            }
            catch (IOException exc)
            {
                Console.WriteLine(exc.Message);
                return;
            }
        }
        try
        {

            Console.WriteLine();
            Console.WriteLine("Here is every other value");
            for(int i=20; i>-20; i-=1)
            {
                f.Seek(i, SeekOrigin.End);
                ch= (char)f.ReadByte();
                Console.Write(ch+" ");
            }
        }
        catch(IOException exc)
        {
            Console.WriteLine(exc.Message);
            return;
        }
        f.Close();
    }
}


How is this block working in the above program
Here the concept of SeekOrigin.End is bit confusing


            for(int i=20; i>-20; i-=1)
            {
                f.Seek(i, SeekOrigin.End);
                ch= (char)f.ReadByte();
                Console.Write(ch+" ");
            }

Reply via email to