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

    public int Addition(int a , int b, int c=10) { return a+b+c; }in above example c is an optional parameter. while calling the method, it is optional to pass value for optional parameter. obj.Add(1,2) would result in 13Note: We can have optional parameter only after all required parameter. we can't have optional parameter at the beginning or at the middle of any required parameter.public int Add(int a=5, int b, int c) is invalid. Similarly, public int Add(int a, int b=5, int c) is also invalid.

    • 0
  • Mahesh Patel
    Nov, 2012 27

    when you declare any function, you have to two types of parameter. one is necessary and second type is option. the require parameter is must passed. but the option parameter is declare as its default value in function definition. to this parameter is not necessary to passed.

    • 0

Most Popular Job Functions