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 hashtable have duplicate keys in c#?
What are the namespace level elements?
What is the difference between dataset and datatable in c#?
What is parsing? How to parse a date time string?
What is literal control
What is orm in c#?
What is the use of the dispose method in C# ?
What do you mean by for each loop?
What is addressof operator?
What are nested classes in c#?
What is collection class c#?
Can we use "this" command within a static method?
Why do we use partial class in c#?
Why is c# a good programming language?
Can we inherit class that contains only one private constructor?