Named Parameter is a new feature of c#, which include in c# 4.0 version. Named parameter are an alternate parameter syntax, which checked for correctness by the compiler. Named arguments enable us to specify the method parameters by their names. When specifying the named arguments, the position of the parameter is not important anymore.
Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace named_parameter_in_c_sharp
{
class student //Create class
{
//Create function with two parameter, where 1st is string type and 2nd is int type
public void show(string Name, int Age)
{
Console.WriteLine("Student Name : {0}\nStudent Age : {1}", Name, Age);
}
}
class Program
{
static void Main(string[] args)
{
student obj = new student();//create object
//Call to function and pass values, where 1st is int type and 2nd is string type
obj.show(Age:20,Name:"Nitin"); // Handle by the named argument
Console.ReadLine();
}
}
}
Output:


Join the conversation! Your thoughts help the community grow.