Amit Kumar
What is Named parameter in C#?
By Amit Kumar in C# on Oct 24 2012
  • Anil Kumar Murmu
    Jan, 2016 15

    Named parameter allows user to pass values in any sequence while calling a method. Say we have a method to add 3 integer.public int Add(int a, int b, int c){return a+b+c;}while calling method we can use syntax: we can have option to call it in any orderobj.Add(a: 2,b: 3,c: 5); obj.Add(b:4,a: 3,c: 7); obj.Add(c: 3,a: 5,d: 2);All are valid statements.However, named parameters should occur after all required parameter only. Hence, following syntax is inappropriate: obj.Add(a:3,7,c:7); is invalid obj.Add(a:4,7,7) is also invalidcorrect approach should be obj.Add(3,b:2,c:2); or obj.Add(3,2,c:5);

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS