command-line argument in C# with Example

Realize: What are Command Line Arguments in C#.Net with Example? Which is utilized to pass messages while calling the executable document from the direction line.

Direction line contention is a significant idea in each programming language. Utilizing this we can pass contentions to fundamental capacity at runtime. As we realize that primary capacity contains contentions of string cluster. It can acknowledge direction line contention from comfort.

command-line argument in C# with Example

Think about the program:

using System;

class Sample
{
	static void Main(string[] args)
	{
		int SUM	= 0;
		int X	= 0;
		int Y	= 0;

		X = Convert.ToInt32(args[0]);
		Y = Convert.ToInt32(args[1]);

		SUM = X + Y;

		Console.WriteLine("Sum is: "+SUM);
		
	}
}

Output:

D:\>sample 10 20
Sum is: 30

In this program, args of principle work acknowledges contention esteems from comfort when we execute the program.

Here, we are passing 10 and 20 as direction line contentions which can be gotten to through args. Where 10 will be allowed into args[0] and 20 will be relegated into args[1].

Leave a Comment

error: Alert: Content is protected!!