<p><sup><strong>Note:</strong> This question was asked at a time when C# did not yet support optional parameters (i.e. before C# 4).</sup></p>

<p>We're building a web API that's programmatically generated from a C# class. The class has method <code>GetFooBar(int a, int b)</code> and the API has a method <code>GetFooBar</code> taking query params like <code>&amp;a=foo &amp;b=bar</code>. </p>

<p>The classes needs to support optional parameters, which isn't supported in C# the language. What's the best approach?</p>

From this site:
https://www.tek-tips.com/viewthread.cfm?qid=1500861
C# does allow the use of the [Optional] attribute (from VB, though not functional in C#). So you can have a method like this:
```
```
using System.Runtime.InteropServices;
public void Foo(int a, int b, [Optional] int c)
{
  ...
}
```
```
In our API wrapper, we detect optional parameters (ParameterInfo p.IsOptional) and set a default value. The goal is to mark parameters as optional without resorting to kludges like having "optional" in the parameter name.