Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give `string[] args` to Linqpad script

Tags:

c#

.net

linqpad

How can I test how my Main method handles command-line arguments in Linqpad? I tried

void Main(string[] args)
{
    args.Dump()
}

but it errors

No overload for method 'Main' takes 0 arguments

Edit: I don't want to run Linqpad from the command-line (that would be tedious), I just want to supply args to the main method somehow (so I can quickly test a Main method). Perhaps like this mock-up:

linqpad args

like image 715
Colonel Panic Avatar asked Sep 21 '12 08:09

Colonel Panic


2 Answers

void Main (string[] args)
{
    #if !CMD
        args = new[] { @"arg1", @"arg2" };
    #endif
    args.Dump();
    ...
like image 64
Den Avatar answered Sep 18 '22 01:09

Den


Why don't you do this:

void Main()
{
    var args = new string[] { "arg_one", "arg_two" };
    subMain(args);
}

// Define other methods and classes here
public void subMain(string[] args){
    args.Dump();
}
like image 26
Alaeddin Hussein Avatar answered Sep 19 '22 01:09

Alaeddin Hussein