w3resource

C#: Learn, how to create a user define function

C# Sharp Function: Exercise-1 with Solution

Write a program in C# Sharp to create a user defined function.

Visual Presentation:

C# Sharp Exercises: Function: Learn, how to create a user define function

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 :

Flowchart: C# Sharp Exercises - Learn, how to create a user define function

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/csharp-exercises/function/csharp-function-exercise-1.php