Main method in c#
In this method static void Main(string[] args) what does the meaning of string[] args ? Where it is used in the program?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Posted Jun 11, 2012, 8:16 PM EDT
For example, you're creating application, which needs to accepts the startup / console parameters then use call the application something like ,
consoleApplication.exe /name:murali /Site:www.c-sharpcorner.com
These values will be passed into the application using , string[] args parameter. It is not necessary to use the args when there is no startup / console parameter for an application.
using System;
class Hello
{
// static Main no return, arguments
public static void Main(string[] args)
{
for (int i = 0; i < args.Length; i++)
{
Console.Write("Args {0}, {1}", i, args[i]);
Console.Write("\n");
}
}
}
Hope this helps you.