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

Difference between directcast and ctype.

725


is it possible to access a remote web service Without UDDI?

737


What are the fundamental principles of oo programming?

774


Does unity use c++ or c#?

644


What is delegates and events?

641






What is the difference between int16 and int32 in c#?

602


Is string nullable c#?

664


Which debugging tools you can use in the .NET ssSDK?

725


What is predicate builder?

659


Explain clr in brief.

706


What are the differences between a class and a struct?

671


Give an example of a ctype.

727


Can we have multiple constructors in a class c#?

658


What is the difference between final finally and finalize in c#?

657


What is nameof c#?

669