0

I have a method like this:

public static void MyMethod(int a, String opt1 = null, byte[] opt2 = null)
{
//code 
} 

I want to call MyMeythod once using opt1, and once using opt2;

MyMethod(3,"param"); call worked but

MyMethod(3,new byte[]); doesn't compile

Is there a way to do this or should I pass opt1 explicitly null

2

2 Answers 2

3

Use the name:

MyMethod(3, opt2: new byte[]);
Sign up to request clarification or add additional context in comments.

Comments

1

In C# 7.3 you can also use another ordering:

MyMethod(opt2: new byte[] { }, a: 3)

2 Comments

Alright Thank you!
@JamalSalman You're welcome!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.