Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional Specification of some C# Optional Parameters

Suppose you have a method with the following signature:

public void SomeMethod(bool foo = false, bool bar = true) { /* ... */ }

When calling this method, is there a way to specify a value for bar and not foo? It would look something like...

SomeMethod(_, false);

... which would translate to...

SometMethod(false, false);

... at compile-time. Is this possible?

like image 894
Anton Avatar asked May 20 '10 18:05

Anton


1 Answers

Take a look at named parameters.

    SomeMethod(bar: false);
like image 156
Ian Mercer Avatar answered Nov 09 '22 01:11

Ian Mercer