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 an example of a delegate?
Why do we use constructors in c#?
Explain async and await?
What is stringbuilder c#?
What is dynamic object in c#?
What is the keyword used to prevent a class from being inherited by another class?
Does c# provide copy constructor?
Is a decimal an integer?
What is data type in c# with example?
Explain what are the steps for creating clr trigger?
What is the default value of decimal in c#?
In dynamic link library, which api is used for load library?
Why data types are important?
If you want to convert a base type to a derived type, what type of conversion do you use?
Can we inherit two classes in c#?