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 the difference between list and arraylist in c#?

481


What is windows forms in c#?

546


What is method and function in c#?

577


Explain boxing and unboxing in c#?

593


What is the .NET collection class that allows an element to be accessed using a unique key?

691






What is difference between events and delegates?

570


What is session and cookies in c#?

602


What is the c# equivalent of c++ catch (…), which was a catch-all statement for any possible exception? Does c# support try-catch-finally blocks?

596


When is a class declared as a class abstract?

655


What is difference between private and protected in c#?

571


What is assembly c#?

555


List some of the basic string operation?

584


what are the differences between a class and structure

633


what is the difference between convert.tostring() and tostring() functions ?

666


What is dependency in software?

606