2
Reply

What is option parameter in C#?

Amit Kumar

Amit Kumar

12y
1.4k
0
Reply

    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.

    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.