Академический Документы
Профессиональный Документы
Культура Документы
5) Now, locate the bin folder of the required application, by using the
following commands. For example, let us imagine that there is a project named ConsoleApplication1 in D: drive.
Hour 13 - Page 1 of 5
19)
However, when the program is invoked, you can pass some arguments to
the Main() method, if required.
You can use these command line arguments for the internal logic in the
application. Application 12: Demo on Main() method arguments
namespace ArgsDemo { class Program { static void Main(string[] args) { if (args.Length > 0) { Console.WriteLine(args.Length + " arguments found. Those are:"); for (int i = 0; i < args.Length; i++) Console.WriteLine(args[i]); } else Console.WriteLine("No arguments found..."); Console.Read(); } } }
Hour 13 - Page 2 of 5
Output:
But, at run time, only one Main() method can be specified as Entry Point.
This specification can be changed using the project properties. To understand better, we start with an example on this.
Hour 13 - Page 3 of 5
Console.WriteLine("This is the Main() method in Program class."); Console.Read(); } } class MySample { static void Main(string[] args) { Console.WriteLine("This is the Main() method in MySample class."); Console.Read(); } } } When this program is compiled, the compiler shows 2 compile time errors.
Its because, two Main() methods are found in MySample class and
Program class; So that the compiler cant understand which Main() method is to be used as exact entry point.
Hour 13 - Page 4 of 5
Then the project properties will be opened. Now, observe the Startup
Object option. The Startup Object option contains two options. 1) (Not Set) 2) MultipleMainMethods.Program
(MultipleMainMethods is the project name).
Now you have to select the required class that contains the desired Main()
method as entry point.
Hour 13 - Page 5 of 5