C# program to demonstrate the use of CanSeek property

Syntax:

bool CanSeek

Example:

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            byte[] b2 = new byte[6];

            FileStream f1;
            FileStream f2;

            f1 = new FileStream("abc.txt", FileMode.Open, FileAccess.Read);
            f2 = new FileStream("xyz.txt", FileMode.Open, FileAccess.Write);

            if (f1.CanSeek)
                Console.WriteLine("Yes, It can be seeked.");
            else
                Console.WriteLine("Yes, It can not seeked.");


            f1.Close();

            if (f2.CanSeek)
                Console.WriteLine("Yes, It can be seeked.");
            else
                Console.WriteLine("Yes, It can not seeked.");


            f2.Close();
        }
    }
}

Output

Yes, It can be seeked.
Yes, It can be seeked.

Leave a Comment

error: Alert: Content is protected!!