Raja G
Raja G

Reputation: 6663

How to set Command Line arguments with C# in Mono IDE .

Hi I am trying to send two arguments with C# by using MONO IDE , But I am unbale to do that . I am getting the following error .

Unhandled Exception: System.IndexOutOfRangeException: Array index is out of range.
  at Command.Main (System.String[] args) [0x00000] in /media/EE76D9DA76D9A39D/C#/Command.cs:6 
[ERROR] FATAL UNHANDLED EXCEPTION: System.IndexOutOfRangeException: Array index is out of range.
  at Command.Main (System.String[] args) [0x00000] in /media/EE76D9DA76D9A39D/C#/Command.cs:6 

Here is my program :

using System;
class Command
{
    static void Main(String[] args)
    {
        Console.WriteLine("Hi {0} , Welcome to {1}",args[0],args[1]);
    }
}

Thanks in advance .

Upvotes: 2

Views: 2060

Answers (2)

konrad.kruczynski
konrad.kruczynski

Reputation: 47641

I believe you mean the MonoDevelop as IDE. If that's true, then go to your project options (either by right clicking on the project and selecting options or via the Project menu and (project name) options position), then go to Run > General and you can put desired parameters in the Parameters edit box.

Upvotes: 5

driis
driis

Reputation: 164331

How are you calling this program ?

If you are just hitting Run in the IDE, it will be run without arguments. Then args will be an empty string array ( string[0]), and therefore you get the exception.

Try calling it from the command line and pass two arguments.

Upvotes: 1

Related Questions