SiteMap  | About    

Quick Interview Questions

What is the execution entry point for a C# console application ?

C# execution entry point

The Main method is the entry point of a C# console application or windows application. When the application is started, the Main method is the first method that is invoked. The Main() method must be static and it should not be public.


class MyFirstClass { static void Main(string[] args) { System.Console.WriteLine("Halo World!!); } }

More about.....C# console based application

Can we create a console application in c# without Main() method ?

No you can't, All executables in .NET need an entry point.

Every C# application must contain a single Main method specifying where program execution is to begin.

Why Main() method is static ?

A static method can be called without instantiating an object. Therefore main() method needs to be static in order to allow it to be the entry to your program.

What is string[] args in Main method ?

C# Interview questions and answers

The string[] args may contain any number of Command line arguments which we want to pass to Main() method. Parameters are read as zero-indexed command-line arguments. For example args[0] will give you the first command line parameter, if there is one. The Main() method can be declared with or without a string[] argument that contains command-line arguments. When using Visual Studio to create Windows Forms applications, you can add the parameter manually or else use the Environment class to obtain the command-line arguments.

What is the use of GetCommandLineArgs() method ? Interview questions and answers

GetCommandLineArgs() returns a string array containing the command-line arguments for the current process. The first element in the array contains the file name of the executing program. The remaining elements contain any additional tokens entered on the command line.


String[] args = Environment.GetCommandLineArgs(); (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.