Skip to content
Discussion options

You must be logged in to vote

I stumbled upon a workaround with attribute DefaultParameterValue, see below.
Using Visual Studio, the default value of the optional parameter is even visible both within and outside the assembly ... very good!

using System.Runtime.InteropServices;
 public class C
 {
     public C()
     {
         MyMethodA();//Test without Parameter
         MyMethodA(2);//Test with parameter
     }
     public void MyMethodA([Optional, DefaultParameterValue(1)] System.Index index) { /*do something*/}
 }

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Aniobodo
Comment options

@Aniobodo
Comment options

@colejohnson66
Comment options

Comment options

You must be logged in to vote
1 reply
@colejohnson66
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Aniobodo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants