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
Can you put two constructor with the same structure in a class?
Explain About Postback
What is the difference between string keyword and system.string class?
What is a property in c#?
Illustrate race condition?
What is a interface in c#?
Which compiler switch creates an xml file from xml comments in the files in an assembly?
What is variable and its classification?
Is cli same as the clr?
Give an example to show for hiding base class methods?
What are "class access modifiers" in C#?
What is different between Implicit conversion and Explicit conversion in C#?
Can constructor have return type c#?
What are object pooling and connection pooling and difference between them?
What are delegate methods?