Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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

C# Sharp Function: Exercise-2 with Solution

Write a program in C# Sharp to create a user define function with parameters.

Pictorial Presentation:

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

Sample Solution:

C# Sharp Code:

using System;
public class funcexer2
{   
    public static void welcome(string name)
    {
        Console.WriteLine("Welcome friend " + name+" !");
    }
    public static void HaveAnice()
    {
        Console.WriteLine("Have a nice day!");
    }
    public static void Main(string[] args)
    {
	  Console.Write("\n\nSee, how to create an user define function with parameters :\n");
      Console.Write("----------------------------------------------------------------\n"); 
	  string str1;
		
      Console.Write("Please input a name : ");
      str1 = Console.ReadLine();	  
      welcome(str1);
      HaveAnice();
    }
}

Sample Output:

See, how to create an user define function with parameters :                                                 
----------------------------------------------------------------                                              
Please input a name : John                                                                                    
Welcome friend John !                                                                                         
Have a nice day!

Flowchart :

Flowchart: C# Sharp Exercises - Learn, how to create an user define function  with parameters

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a program in C# Sharp to create a user define function.
Next: Write a program in C# Sharp to create a function for the sum of two numbers.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.