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 event sourcing in c#?

498


What is the use of functional interface?

477


How long can a string be c#?

507


What is the difference between method and constructor in c#?

456


Explain the difference between abstract class and interface in .net?

468






What is base class in c#?

538


Why delegates are required?

532


What is parsing? How to parse a date time string?

534


Define encapsulation?

650


What is singleordefault c#?

504


Why do we need escape characters?

481


Define Final Class in C#

542


Explain the difference between the debug class and trace class?

492


What is use of console?

460


I need code to connect ohter systems in the LAN and i want to display my website image over there and i want explain as a admin through phone. So i need code to access other system using C-Sharp. Any one please help me.Please give me the code. Advace thanks.

1458