Can overrride the Main method

Answer Posted / shashi bhushan vishwakarma(tus

we can not override the Main method but we can use multiple
Main method within the same class also and within the same
namespace also.
ex.
namespace ConsoleApplication1
{
class Program
{
public void Main()
{
Console.WriteLine("hello");
}
public static void Main(string[] args)
{
Console.WriteLine("hello c# 2010");

Program o = new Program();
o.Main();
Console.ReadLine();

}
}
}

Output:
hello c# 2010
hello

another Ex.

namespace ConsoleApplication1
{
class Program
{

public static void Main(string[] args)
{
Console.WriteLine("hello c# 2010");

a obj = new a();
obj.Main();
Console.ReadLine();

}
}


class a:Program
{
public void Main()
{
Console.WriteLine("hello");
}

}
}

output:
hello c# 2010
hello

Is This Answer Correct ?    17 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is public, private, protected, internal and internal protected?

531


What is virtual in c#?

480


What is multicast delegate in c# ?

523


Is learning c# hard?

510


List down the different ide’s provided by microsoft for c# development.

475






Define a partial class?

506


What is file extension of webservices?

578


Explain About delegates

598


What is a method signature in c#?

511


What is application object in c#?

507


Are c# strings immutable?

489


what is the difference between .dll and .exe

531


What is the difference between array and arraylist c#?

468


What is datetime minvalue in c#?

573


Is c sharp and c# are same?

514