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
What is namespace c#?
Distinguish between array and arraylist in c#?
What are extender provider components? Explain how to use an extender provider in the project.
What is concrete class in c# with example?
What is for loop in c#?
What is the difference between const and static read-only?
What is the use of parse in c#?
Can an abstract class have a constructor c#?
What is the difference between System.console.WriteLine() and System.console.Write() function?example?
Is string nullable c#?
what is object-oriented programming (oop) language?
What is difference between ilist and list?
Is c sharp open source?
Which is more efficient for loop or while loop?
How is the syntax written to inherit from a class in C#?Give an example ?