Because args[0] is getting your first argument. If it is not there the
size of the array ==0. Try args.Length to see how many arguments there
are.
--
Peter
On Tue, Nov 4, 2008 at 7:02 AM, VIKAS GARG <[EMAIL PROTECTED]> wrote:
> using System;
> using System.IO;
> class ShowFile
> {
> public static void Main(string[] args)
> {
> int i;
> FileStream fin;
> try
> {
> fin = new FileStream(args[0], FileMode.Open);
> }
> catch (FileNotFoundException exc)
> {
> Console.WriteLine(exc.Message);
> return;
> }
> catch (IndexOutOfRangeException exc)
> {
> Console.WriteLine(exc.Message + "\nUsage: ShowFile File");
> return;
> }
> // read bytes until EOF is encountered
> do
> {
> try
> {
> i = fin.ReadByte();
> }
> catch (Exception exc)
> {
> Console.WriteLine(exc.Message);
> return;
> }
> if (i != -1) Console.Write((char)i);
> } while (i != -1);
> fin.Close();
> }
> }
>
>
>
> In such kind of progg where we are required to give the name of the file at
> the runtime and if we don't provide the name of the file, why it gives error
> "Index was outside the bounds of array"