class Program
{
static void Main(string[] args)
{
Hello();
}
}
Compile Error::
The name 'Hello' does not exist in the current context
So, make sure that before calling a function create it first. Then call the function as shown bellow.
class Program
{
static void Main(string[] args)
{
//Calling Welcome function
Hello();
Console.ReadKey();
}
///
/// Welcome Message
///
static void Hello()
{
Console.WriteLine("Hello World");
}
}
Output
Hello World
Lets go other way calling multi-functions from Main() method as shown below.
class Program
{
static void Main(string[] args)
{
//Calling Welcome function
Hello();
VisitAgain();
Hello();
Console.ReadKey();
}
///
/// Welcome Message
///
static void Hello()
{
Console.WriteLine("Hello World");
}
///
/// Good Bye Message
///
static void VisitAgain()
{
Console.WriteLine("Good Bye, Visit again");
}
}
OutPut
Hello World
Good Bye, Visit againHello World
Lets work differently like calling VisitAgain() function from Hello() function not from Main() as shown below.
class Program
{
static void Main(string[] args)
{
//Calling Welcome function
Hello();
Console.ReadKey();
}
///
/// Welcome Message
///
static void Hello()
{
Console.WriteLine("Hello World");
VisitAgain();
}
///
/// Good Bye Message
///
static void VisitAgain()
{
Console.WriteLine("Good Bye, Visit again");
}
}
OutPut
Hello World
Good Bye, Visit again
No comments:
Post a Comment