C# Main Function
In this chapter you will learn:
- Four types of man functions
- Syntax for Main functions
- Example for Main functions
- Using foreach to loop through the parameter from Main function
Description
All C# applications begin execution by calling Main( ). Main is the entry point method for a C# application.
Syntax
C# console application regards the following signatures for its entry main function:
public static void Main();
public static void Main(string[] args);
public static int Main();
public static int Main(string[] args);
Example
The main function returning an int status.
using System;// w ww . ja va2 s .c om
class MainClass
{
public static int Main()
{
Console.WriteLine("Hello, Universe!");
return(0);
}
}
The code above generates the following result.
Example 2
using System;// ww w.j a va 2 s . c o m
class Program
{
static void Main(string[] args)
{
Console.WriteLine(args.Length);
foreach (string arg in args){
Console.WriteLine(arg);
}
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- What are Extension Methods
- Syntax to create Extension Methods
- Example
- Extension methods versus instance methods