C#: Learn, how to create a user define function
Write a program in C# Sharp to create a user defined function.
Visual Presentation:
Sample Solution:
C# Sharp Code:
using System;
// Define a class named 'funcexer1'
class funcexer1
{
// Define a public static method 'welcome' that prints a welcome message
public static void welcome()
{
Console.WriteLine("Welcome Friends!");
}
// Define a public static method 'HaveAnice' that prints a message for a nice day
public static void HaveAnice()
{
Console.WriteLine("Have a nice day!");
}
// Main method, the entry point of the program
public static void Main()
{
// Print a description of the program
Console.Write("\n\nSee, how to create an user define function :\n");
Console.Write("------------------------------------------------\n");
// Call the 'welcome' method to print the welcome message
welcome();
// Call the 'HaveAnice' method to print the message for a nice day
HaveAnice();
// Print a new line
Console.Write("\n");
}
}
Sample Output:
See, how to create an user define function : ------------------------------------------------ Welcome Friends! Have a nice day!
Flowchart :
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: C# Sharp programming exercises Function with Solution.
Next: Write a program in C# Sharp to create a user define function with parameters.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics