
- 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
Command Line arguments in C#
If you want to pass arguments by command line, then use command line arguments in C# −
When we create a program in c#, static void main is used and we can see the arguments in it .
class HelloWorld { static void Main(string[] args) { /* my first program in C# */ Console.WriteLine("Hello World"); Console.ReadKey(); }
The string[] args is a variable that has all the values passed from the command line as shown above.
Now to print those arguments, let’s say we have an argument, “One” −
Console.WriteLine("Length of the arguments: "+args.Length); Console.WriteLine("Arguments:"); foreach (Object obj in args) { Console.WriteLine(obj); }
The above will print −
Length of the arguments: 1 Arguments: One
- Related Articles
- Command Line Arguments in Python
- Command line arguments in Java
- Command Line arguments in Lua
- Java command line arguments
- Command line arguments in C/C++
- Command line arguments example in C
- Explain Java command line arguments.
- Command Line and Variable Arguments in Python?
- Command Line arguments in Java programming\n
- How to Parse Command Line Arguments in C++?
- How to add command line arguments in Python?
- Parse Command Line Arguments in Bash on Linux
- getopt() function in C to parse command line arguments
- How do we access command line arguments in Python?
- How command line arguments are passed in main method in C#?

Advertisements