Multiple optional parameters calling function

MonsterMMORPG picture MonsterMMORPG · Jul 18, 2013 · Viewed 23.3k times · Source

Assume that i have a function like this below It takes 3 parameters and 2 have optional values

private void  myfunc (int a, int b=2, int c=3)
{
  //do some stuff here related to a,b,c
}

now i want to call this function like below how possible ?

myfunc(3,,5)

So i want it to use default parameter b=2

But it is giving error that way.

Here the error message

Argument missing

C# 4.5

Answer

It'sNotALie. picture It'sNotALie. · Jul 18, 2013

You need to use named parameters, like so:

myfunc(a, c:5);