
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How command line arguments are passed in main method in C#?
The Main() method is the entry point −
static void Main(string[] args)
The arguments array args is used to set arguments −
string[] args)
It will set the following if you add two arguments −
var args = new string[] {"arg1","arg2”}
Here is the demo code −
Example
using System; namespace Demo { class HelloWorld { // args for command line static void Main(string[] args) { Console.WriteLine("Welcome here!"); Console.ReadKey(); } } }
To compile a C# program by using the command-line instead of the Visual Studio IDE −
Open a text editor and add the above-mentioned code.
Save the file as helloworld.cs
Open the command prompt tool and go to the directory where you saved the file.
Type csc helloworld.cs and press enter to compile your code.
If there are no errors in your code, the command prompt takes you to the next line and generates helloworld.exe executable file.
Type helloworld to execute your program.
You can see the output Hello World printed on the screen.
- Related Articles
- Command Line Arguments in Python
- Command line arguments in Java
- Command Line arguments in C#
- Command Line arguments in Lua
- Command line arguments in C/C++
- Command line arguments example in C
- Java command line arguments
- How to Parse Command Line Arguments in C++?
- How to add command line arguments in Python?
- How do we access command line arguments in Python?
- Command Line and Variable Arguments in Python?
- Command Line arguments in Java programming\n
- Explain Java command line arguments.
- getopt() function in C to parse command line arguments
- How are arguments passed by value or by reference in Python?

Advertisements