Command Line Arguments In C# Complete Guide

 Last Update:2025-06-23T00:00:00     .NET School AI Teacher - SELECT ANY TEXT TO EXPLANATION.    15 mins read      Difficulty-Level: beginner

Understanding the Core Concepts of Command Line Arguments in C#

Command Line Arguments in C# - Explained in Detail with Important Information

Overview

Usage

To utilize command line arguments in a C# program, you need to modify the Main method to accept either a single string array parameter (string[] args) or a variable number of parameters using the string type followed by the params keyword (string params args). This enables the application to receive input that can be processed at runtime.

Example:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Number of arguments: " + args.Length);
        for(int i = 0; i < args.Length; i++)
        {
            Console.WriteLine($" Argument {i + 1}: {args[i]}");
        }
    }
}

In the above example, the application prints the number of arguments passed along with each argument itself.

Accessing Command Line Arguments

Once a C# application receives command line arguments, they can be accessed through the indices of the args array, similar to how you would access elements in any other array.

Example: Considering the command myprogram.exe arg1 arg2 arg3, within your application:

  • args[0] would contain "arg1"
  • args[1] would contain "arg2"
  • args[2] would contain "arg3"

This feature is especially useful for creating command-line tools or applications that need configuration options before starting execution.

Common Use Cases

  • Configuration: Supply configuration parameters that determine how the application behaves.
  • File Paths: Provide paths to files that the application needs to process.
  • Commands: Execute specific commands or perform particular actions based on the arguments provided.
  • Batch Processing: Handle batch processing tasks with user inputs passed from the command line.

Parsing Command Line Arguments

Parsing command line arguments involves converting the received strings into the appropriate data types and structures for use within your application. You may need to validate arguments to ensure they meet expected criteria before further action is taken.

Libraries:

  • Microsoft.Extensions.CommandLineUtils: Provides advanced parsing capabilities and supports options and commands.
  • CommandLineParser: An alternative library that allows defining argument structure using attributes and generates detailed help messages.

Example using Microsoft.Extensions.CommandLineUtils:

using Microsoft.Extensions.CommandLineUtils;

class Program
{
    static void Main(string[] args)
    {
        CommandLineApplication app = new CommandLineApplication();

        CommandOption nameOption =
            app.Option("-n|--name <name>", 
                       "The name to greet.",
                       CommandOptionType.SingleValue);

        app.OnExecute(() => 
        {
            var name = nameOption.Value();
            if (string.IsNullOrEmpty(name))
                name = "World";

            Console.WriteLine($"Hello, {name}!");
            return 0;
        });

        app.Execute(args);
    }
}

Handling Special Characters

When passing arguments that include special characters such as spaces, quotes, or semicolons, you must ensure they are correctly interpreted by the command line parser.

  • Spaces: Surround words containing spaces with quotes.
    myprogram.exe "first argument"
    
  • Quotes: Use double quotes around arguments that include double quotes and escape them.
    myprogram.exe "He said \"Hi\""
    
  • Semicolons: Semicolons terminate commands; escape them if required as part of an argument.
    myprogram.exe "C:\MyFolder\file;1.txt"
    

Note: Always be cautious when handling raw input to avoid injection attacks.

Environment Variables vs. Command Line Arguments

While both environment variables and command line arguments provide ways to pass input into an application, they differ in scope and usage:

  • Environment Variables: Persistent across all applications running on the system within the same session and can be inherited by child processes.
  • Command Line Arguments: Specific to a single invocation of an executable and are not accessible to other processes unless explicitly shared.

Best Practices

  • Validation: Validate arguments for correctness and completeness before proceeding with operations.
  • Help Messages: Implement comprehensive help messages to guide users on how to use the application properly.
  • Error Handling: Add robust error handling mechanisms to gracefully manage invalid or unexpected inputs.
  • Logging: Use logging to capture command line arguments for troubleshooting purposes without exposing sensitive information.

Examples:

Here are a few examples demonstrating various aspects of command line arguments handling in C#:

Example 1: Simple Argument Count:

static void Main(string[] args)
{
    Console.WriteLine("Arguments received: " + args.Length);
}

When running:

myprogram.exe arg1 arg2

It outputs:

Arguments received: 2

Example 2: Advanced Parsing: Using the Microsoft.Extensions.CommandLineUtils library for structured argument handling:

using Microsoft.Extensions.CommandLineUtils;

class Program
{
    static int Main(string[] args)
    {
        CommandLineApplication app = new CommandLineApplication();

        app.Command("greet", (command) =>
        {
            CommandOption nameOption =
                command.Option("-n|--name <name>",
                               "The name to greet",
                               CommandOptionType.SingleValue);

            command.OnExecute(() =>
            {
                string name = nameOption.Value() ?? "World";
                Console.WriteLine($"Hello {name}!");
                return 0;
            });
        });

        return app.Execute(args);
    }
}

When running:

myprogram.exe greet -n Alice

It outputs:

Hello Alice!

Conclusion

Command Line Arguments in C# offer a powerful way to interact with applications through the terminal. By understanding how to handle and parse these arguments, developers can create flexible, configurable, and efficient apps suitable for various scenarios, including automated scripts and batch processing tasks. Utilizing libraries like Microsoft.Extensions.CommandLineUtils can simplify the argument parsing process and enhance the functionality of CLI applications.


Online Code run

🔔 Note: Select your programming language to check or run code at

💻 Run Code Compiler

Step-by-Step Guide: How to Implement Command Line Arguments in C#

Table of Contents

  1. Basic Setup
  2. Accessing Command Line Arguments
  3. Parsing Command Line Arguments
  4. Performing Actions Based on Arguments
  5. Adding Help Text
  6. Handling Optional Arguments
  7. Error Handling for Arguments

1. Basic Setup

First, ensure you have the .NET SDK installed. If you don't, you can download it from the .NET website.

Step 1: Create a New Console Application

Open a terminal and run the following commands:

dotnet new console -n CommandLineArgumentsDemo
cd CommandLineArgumentsDemo

Step 2: Open the Project in Your Preferred Editor

For this guide, I'll assume you're using the terminal and Visual Studio Code. You can open the project by running:

code .

Or, if you prefer another editor, open the CommandLineArgumentsDemo.csproj file.

2. Accessing Command Line Arguments

By default, C# applications do not access command line arguments. We need to modify the Program.cs file to include them.

Modify Program.cs

Replace the contents of Program.cs with the following code:

using System;

namespace CommandLineArgumentsDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Number of arguments passed: " + args.Length);

            for (int i = 0; i < args.Length; i++)
            {
                Console.WriteLine($"Argument {i}: {args[i]}");
            }
        }
    }
}

Run the Application

From the terminal, run the application with some command line arguments:

dotnet run -- arg1 arg2 arg3

Expected Output:

Number of arguments passed: 3
Argument 0: arg1
Argument 1: arg2
Argument 2: arg3

3. Parsing Command Line Arguments

Parsing means interpreting the input arguments and converting them into meaningful data that the application can use.

Example: Summing Numbers from Arguments

Replace the contents of Program.cs with the following code:

using System;

namespace CommandLineArgumentsDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("No arguments provided. Please provide numbers to sum.");
                return;
            }

            double sum = 0;
            bool isValidNumber;

            foreach (var arg in args)
            {
                isValidNumber = double.TryParse(arg, out double number);
                if (isValidNumber)
                {
                    sum += number;
                }
                else
                {
                    Console.WriteLine($"'{arg}' is not a valid number and will be ignored.");
                }
            }

            Console.WriteLine("Sum of valid numbers: " + sum);
        }
    }
}

Run the Application

Test the application with a mix of valid and invalid numbers:

dotnet run -- 10 20.5 invalid 30

Expected Output:

'invalid' is not a valid number and will be ignored.
Sum of valid numbers: 60.5

4. Performing Actions Based on Arguments

Let's create a simple calculator that performs different operations based on the command line arguments.

Replace Program.cs

using System;

namespace CommandLineArgumentsDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Usage: dotnet run -- <operation> <number1> <number2>");
                Console.WriteLine("<operation> can be: add, subtract, multiply, divide");
                return;
            }

            string operation = args[0].ToLower();
            double number1;
            double number2;

            if (!double.TryParse(args[1], out number1) || !double.TryParse(args[2], out number2))
            {
                Console.WriteLine("Please provide valid numbers for <number1> and <number2>.");
                return;
            }

            double result;
            bool success = PerformOperation(operation, number1, number2, out result);

            if (success)
            {
                Console.WriteLine($"Result: {result}");
            }
        }

        static bool PerformOperation(string operation, double num1, double num2, out double result)
        {
            switch (operation)
            {
                case "add":
                    result = num1 + num2;
                    return true;
                case "subtract":
                    result = num1 - num2;
                    return true;
                case "multiply":
                    result = num1 * num2;
                    return true;
                case "divide":
                    if (num2 == 0)
                    {
                        Console.WriteLine("Cannot divide by zero.");
                        result = 0;
                        return false;
                    }
                    result = num1 / num2;
                    return true;
                default:
                    Console.WriteLine($"Unhandled operation: {operation}");
                    result = 0;
                    return false;
            }
        }
    }
}

Run the Application

Perform different operations:

dotnet run -- add 10 20
dotnet run -- subtract 10 20
dotnet run -- multiply 10 20
dotnet run -- divide 10 20
dotnet run -- divide 10 0

Expected Output:

Result: 30
Result: -10
Result: 200
Result: 0.5
Cannot divide by zero.

5. Adding Help Text

Help text is crucial for users to understand how to use the application.

Modify Program.cs

Add a ShowHelp method to display help information.

using System;

namespace CommandLineArgumentsDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0 || args[0] == "--help" || args[0] == "-h")
            {
                ShowHelp();
                return;
            }

            if (args.Length != 3)
            {
                Console.WriteLine("Incorrect number of arguments. Use --help for usage.");
                return;
            }

            string operation = args[0].ToLower();
            double number1;
            double number2;

            if (!double.TryParse(args[1], out number1) || !double.TryParse(args[2], out number2))
            {
                Console.WriteLine("Please provide valid numbers for <number1> and <number2>.");
                return;
            }

            double result;
            bool success = PerformOperation(operation, number1, number2, out result);

            if (success)
            {
                Console.WriteLine($"Result: {result}");
            }
        }

        static void ShowHelp()
        {
            Console.WriteLine("Usage: dotnet run -- <operation> <number1> <number2>");
            Console.WriteLine("Operations:");
            Console.WriteLine("  add       - Add the two numbers");
            Console.WriteLine("  subtract  - Subtract the second number from the first");
            Console.WriteLine("  multiply  - Multiply the two numbers");
            Console.WriteLine("  divide    - Divide the first number by the second");
        }

        static bool PerformOperation(string operation, double num1, double num2, out double result)
        {
            switch (operation)
            {
                case "add":
                    result = num1 + num2;
                    return true;
                case "subtract":
                    result = num1 - num2;
                    return true;
                case "multiply":
                    result = num1 * num2;
                    return true;
                case "divide":
                    if (num2 == 0)
                    {
                        Console.WriteLine("Cannot divide by zero.");
                        result = 0;
                        return false;
                    }
                    result = num1 / num2;
                    return true;
                default:
                    Console.WriteLine($"Unhandled operation: {operation}");
                    result = 0;
                    return false;
            }
        }
    }
}

Run the Application with Help

Check the help text:

dotnet run -- --help
dotnet run -- -h

Expected Output:

Usage: dotnet run -- <operation> <number1> <number2>
Operations:
  add       - Add the two numbers
  subtract  - Subtract the second number from the first
  multiply  - Multiply the two numbers
  divide    - Divide the first number by the second

6. Handling Optional Arguments

Optional arguments allow users to provide additional options without breaking the application if they don't include them.

Example: Enable Debug Mode

We'll add a -debug option to print additional debug information.

Modify Program.cs

using System;

namespace CommandLineArgumentsDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            bool debugMode = false;
            string operation = string.Empty;
            double number1 = 0;
            double number2 = 0;
            int indexOffset = 0;

            if (args.Length == 0)
            {
                Console.WriteLine("No arguments provided. Please provide at least operation and two numbers.");
                ShowHelp();
                return;
            }

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLower())
                {
                    case "-debug":
                        debugMode = true;
                        break;
                    default:
                        // Assume the first argument after flags is the operation
                        if (operation == string.Empty)
                        {
                            operation = args[i];
                        }
                        // Subsequent arguments are numbers
                        else if (indexOffset == 0)
                        {
                            if (!double.TryParse(args[i], out number1))
                            {
                                Console.WriteLine("Invalid number provided for <number1>.");
                                return;
                            }
                            indexOffset++;
                        }
                        else if (indexOffset == 1)
                        {
                            if (!double.TryParse(args[i], out number2))
                            {
                                Console.WriteLine("Invalid number provided for <number2>.");
                                return;
                            }
                            indexOffset++;
                        }
                        else
                        {
                            Console.WriteLine("Too many arguments provided.");
                            ShowHelp();
                            return;
                        }
                        break;
                }
            }

            if (operation == string.Empty || indexOffset < 2)
            {
                Console.WriteLine("Missing required arguments. See usage.");
                ShowHelp();
                return;
            }

            if (debugMode)
            {
                Console.WriteLine("Debug Mode: Enabled");
                Console.WriteLine($"Operation: {operation}");
                Console.WriteLine($"Number 1: {number1}");
                Console.WriteLine($"Number 2: {number2}");
            }

            double result;
            bool success = PerformOperation(operation, number1, number2, out result);

            if (success)
            {
                Console.WriteLine($"Result: {result}");
            }
        }

        static void ShowHelp()
        {
            Console.WriteLine("Usage: dotnet run -- [-debug] <operation> <number1> <number2>");
            Console.WriteLine("Operations:");
            Console.WriteLine("  add       - Add the two numbers");
            Console.WriteLine("  subtract  - Subtract the second number from the first");
            Console.WriteLine("  multiply  - Multiply the two numbers");
            Console.WriteLine("  divide    - Divide the first number by the second");
        }

        static bool PerformOperation(string operation, double num1, double num2, out double result)
        {
            switch (operation)
            {
                case "add":
                    result = num1 + num2;
                    return true;
                case "subtract":
                    result = num1 - num2;
                    return true;
                case "multiply":
                    result = num1 * num2;
                    return true;
                case "divide":
                    if (num2 == 0)
                    {
                        Console.WriteLine("Cannot divide by zero.");
                        result = 0;
                        return false;
                    }
                    result = num1 / num2;
                    return true;
                default:
                    Console.WriteLine($"Unhandled operation: {operation}");
                    result = 0;
                    return false;
            }
        }
    }
}

Run the Application with Debug Mode

dotnet run -- -debug add 10 20
dotnet run -- add 10 20

Expected Output:

Debug Mode: Enabled
Operation: add
Number 1: 10
Number 2: 20
Result: 30

Result: 30

7. Error Handling for Arguments

Robust applications handle errors gracefully. Let's add comprehensive error handling for the calculator application.

Final Version of Program.cs

using System;

namespace CommandLineArgumentsDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            bool debugMode = false;
            string operation = string.Empty;
            double number1 = 0;
            double number2 = 0;
            bool operationFound = false;
            bool number1Provided = false;
            bool number2Provided = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLower())
                {
                    case "-debug":
                        debugMode = true;
                        break;
                    default:
                        // Check if it's an operation
                        if (operation == string.Empty && !operationFound)
                        {
                            operation = args[i].ToLower();
                            operationFound = true;
                        }
                        // Otherwise, it's a number
                        else
                        {
                            double parsedNumber;
                            if (double.TryParse(args[i], out parsedNumber))
                            {
                                if (!number1Provided)
                                {
                                    number1 = parsedNumber;
                                    number1Provided = true;
                                }
                                else if (!number2Provided)
                                {
                                    number2 = parsedNumber;
                                    number2Provided = true;
                                }
                                else
                                {
                                    Console.WriteLine("Too many arguments provided. See usage.");
                                    ShowHelp();
                                    return;
                                }
                            }
                            else
                            {
                                Console.WriteLine($"'{args[i]}' is not a valid number.");
                                ShowHelp();
                                return;
                            }
                        }
                        break;
                }
            }

            if (!operationFound)
            {
                Console.WriteLine("No operation provided. See usage.");
                ShowHelp();
                return;
            }

            if (!number1Provided || !number2Provided)
            {
                Console.WriteLine("Insufficient numbers provided. Please provide exactly two numbers.");
                ShowHelp();
                return;
            }

            if (debugMode)
            {
                Console.WriteLine("Debug Mode: Enabled");
                Console.WriteLine($"Operation: {operation}");
                Console.WriteLine($"Number 1: {number1}");
                Console.WriteLine($"Number 2: {number2}");
            }

            double result;
            bool success = PerformOperation(operation, number1, number2, out result);

            if (success)
            {
                Console.WriteLine($"Result: {result}");
            }
        }

        static void ShowHelp()
        {
            Console.WriteLine("Usage: dotnet run -- [-debug] <operation> <number1> <number2>");
            Console.WriteLine("Operations:");
            Console.WriteLine("  add       - Add the two numbers");
            Console.WriteLine("  subtract  - Subtract the second number from the first");
            Console.WriteLine("  multiply  - Multiply the two numbers");
            Console.WriteLine("  divide    - Divide the first number by the second");
        }

        static bool PerformOperation(string operation, double num1, double num2, out double result)
        {
            switch (operation)
            {
                case "add":
                    result = num1 + num2;
                    return true;
                case "subtract":
                    result = num1 - num2;
                    return true;
                case "multiply":
                    result = num1 * num2;
                    return true;
                case "divide":
                    if (num2 == 0)
                    {
                        Console.WriteLine("Cannot divide by zero.");
                        result = 0;
                        return false;
                    }
                    result = num1 / num2;
                    return true;
                default:
                    Console.WriteLine($"Unhandled operation: {operation}");
                    result = 0;
                    return false;
            }
        }
    }
}

Explanation of Changes

  1. Flags and Arguments Separation: The application now distinguishes between flags like -debug and actual arguments (operation and numbers).
  2. Comprehensive Checks: The application checks if all required arguments are provided and if any unexpected arguments are given.
  3. Specific Error Messages: Each error case provides a specific message to help users correct their input.

Run the Application with Different Scenarios

dotnet run -- --debug add 10 20
dotnet run -- add 10
dotnet run -- add 10 20 30
dotnet run -- invalid 10 20
dotnet run -- add a 20
dotnet run -- add 10 0 --debug

Expected Output:

Debug Mode: Enabled
Operation: add
Number 1: 10
Number 2: 20
Result: 30

No operation provided. See usage.
Usage: dotnet run -- [-debug] <operation> <number1> <number2>
Operations:
  add       - Add the two numbers
  subtract  - Subtract the second number from the first
  multiply  - Multiply the two numbers
  divide    - Divide the first number by the second

Too many arguments provided. See usage.
Usage: dotnet run -- [-debug] <operation> <number1> <number2>
Operations:
  add       - Add the two numbers
  subtract  - Subtract the second number from the first
  multiply  - Multiply the two numbers
  divide    - Divide the first number by the second

Unhandled operation: invalid
Usage: dotnet run -- [-debug] <operation> <number1> <number2>
Operations:
  add       - Add the two numbers
  subtract  - Subtract the second number from the first
  multiply  - Multiply the two numbers
  divide    - Divide the first number by the second

'a' is not a valid number.
Usage: dotnet run -- [-debug] <operation> <number1> <number2>
Operations:
  add       - Add the two numbers
  subtract  - Subtract the second number from the first
  multiply  - Multiply the two numbers
  divide    - Divide the first number by the second

Cannot divide by zero.
Result: 0

Conclusion

You've now learned how to handle command line arguments in C#. You've created a simple yet functional calculator that supports various operations, optional flags, and provides comprehensive help and error messages. This skill is invaluable when you need to build command-line utilities or integrate user input directly via the console.

Feel free to expand upon these examples or adapt them to suit your specific needs. Happy coding! 🚀🚀🚀

Additional Resources

Top 10 Interview Questions & Answers on Command Line Arguments in C#

1. What are Command Line Arguments in C#?

Answer: Command Line Arguments refer to the arguments or parameters passed to a C# application when it is launched from a command line interface (such as Command Prompt or Terminal). These arguments can be used to pass data or options to the application at runtime, allowing it to perform different tasks based on the input provided.

2. How do you access Command Line Arguments in a C# Program?

Answer: In C#, command line arguments can be accessed through the Main method by using a string[] array as a parameter. The typical signature of the Main method that accepts command line arguments is:

static void Main(string[] args)
{
    // args contains the command line arguments
}

Each element in the args array represents a separate argument passed to the program.

3. Can a C# Program have more than one Main() method?

Answer: No, a C# program cannot have more than one entry point (i.e., more than one Main() method). The Main() method serves as the starting point for program execution, and having multiple Main() methods would cause a compilation error, unless they are marked with [STAThread] or [MTAThread], which defines them as alternative entry points for COM components, not for the main program execution.

4. How many arguments can you pass through the command line in C#?

Answer: There isn't a strict limit imposed by C# on the number of command line arguments you can pass, but the actual limit is determined by the operating system. For Windows, this limit is typically around 8191 characters for the entire command line string, including the path to the executable.

5. What happens if no command line arguments are passed?

Answer: If no command line arguments are passed when a C# application starts, the args array will simply be empty (args.Length == 0). Your application should handle such cases gracefully to avoid runtime errors.

6. Can Command Line Arguments contain spaces?

Answer: Yes, command line arguments can contain spaces, but if spaces are required within a single argument, the argument should be enclosed in quotes (single or double). For example:

dotnet run "Hello World" Test 123

This command passes three arguments: "Hello World", Test, and 123.

7. What libraries in C# help process Command Line Arguments?

Answer: While you can manually parse command line arguments from the args array in the Main method, C# provides several libraries to simplify this task:

  • System.CommandLine: A modern library designed to make command line interfaces simple, flexible, and powerful.
  • NDesk.Options: An open-source library that allows parsing command line options.
  • CommandLineParser: A popular NuGet package specifically for parsing command line arguments into POCO (Plain Old CLR Objects).

8. How can I validate Command Line Arguments?

Answer: Validating command line arguments is crucial to ensure your application receives the correct input. You can implement validation manually using conditional statements (if-else), regular expressions, etc., or utilize libraries like System.CommandLine for more structured and declarative validation. Here's an example of manual validation:

static void Main(string[] args)
{
    if (args.Length < 1)
    {
        Console.WriteLine("Please provide at least one argument.");
        return;
    }

    int value;
    if (int.TryParse(args[0], out value))
    {
        Console.WriteLine($"Valid integer received: {value}");
    }
    else
    {
        Console.WriteLine("The provided argument was not a valid integer.");
    }
}

9. How do I get the name/path of the executable itself using command line arguments?

Answer: The args array does not include the name or path of the executable itself; it only contains the arguments passed after it. To obtain the executable path, you can use Environment.GetCommandLineArgs(), or better yet, AppDomain.CurrentDomain.FriendlyName to get just the name and Assembly.GetExecutingAssembly().Location for the full path:

using System;
using System.Reflection;

static void Main(string[] args)
{
    // Using Environment
    string[] allArgs = Environment.GetCommandLineArgs();
    string exePathFromEnv = allArgs[0];

    // Using AppDomain
    string appName = AppDomain.CurrentDomain.FriendlyName;

    // Using Assembly
    string exePath = Assembly.GetExecutingAssembly().Location;

    Console.WriteLine($"Executable path (Environment): {exePathFromEnv}");
    Console.WriteLine($"Application name (AppDomain): {appName}");
    Console.WriteLine($"Executable path (Assembly): {exePath}");
}

10. How can I handle optional command line arguments in C#?

Answer: Handling optional command line arguments involves checking if the argument is present in the args array and providing default values or alternative actions when it is missing. Libraries such as System.CommandLine and CommandLineParser offer built-in support for optional arguments. Here's how you might do it manually:

static void Main(string[] args)
{
    string configPath = "default.config";

    // Check if the user has specified a configuration file
    if (args.Length > 0 && args[0] != "-config")
    {
        configPath = args[0];
    }
    else if (args.Length > 1 && args[0] == "-config")
    {
        configPath = args[1];
    }

    Console.WriteLine($"Using configuration file: {configPath}");
}

In this example, the program expects an optional configuration file path either directly first or by specifying a -config flag followed by the path.

Conclusion:

You May Like This Related .NET Topic

Login to post a comment.