Pass Arguments To a C# Application From The Command-Line

Passing arguments to a C# .NET application from the command line can help pass values and variables and process information.

By default, the main function has a built-in option to accept arguments without modifying or writing extra code.

The following code example shows a program that accepts arguments via the command line and prints them out.

using System;
namespace passargs
    class Program
        static void Main(string[] args)
            Console.WriteLine($"You passed {args.Length} arguments");
            foreach(string count in args)

Pass Arguments

To pass arguments to the command, I am using the dotnet run command with the arguments as shown below.

dotnet run green blue yellow

To pass arguments to a published app run this line.

dotnet passargs.dll blue

The output is shown below.

You passed 3 arguments

1 thought on “Pass Arguments To a C# Application From The Command-Line”

Comments are closed.