Sponsored Ad

Friday, October 23, 2009

C# Multiple Main() Methods

When a C# console or Windows application is compiled, by default the compiler looks for exactly four Main() technique in any class matching the signature that was described and makes that class technique the entry point for the program. If there is more than four Main() technique, the compiler will return an error message. For example, consider the following code called MainExample.cs :

 

using System;
namespace Wrox.ProCSharp.Basics
{
class Client
{
public static int Main()
{
MathExample.Main();
return 0;
}
}
class MathExample
{
static int Add(int x, int y)
{
return x + y;
}
public static int Main()

{
int i = Add(5,10);
Console.WriteLine(i);
return 0;
}
}
}

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers