1

I have two functions which differ only in their second parameter. Example:

public IEnumerable<Thing> Get(string clause, List<Things> list)
{
}

public IEnumerable<Thing> Get(string clause, List<OtherThing> list)
{
}

I want to call the first instance of this function, but I want to pass null as the second parameter. Is there a way to specify the "type" of null?

bpeikes
  • 3,014
  • 6
  • 36
  • 71

1 Answers1

8

Cast the null literal:

Get("", (List<Things>)null)

store it in a variable first:

List<Things> list = null;
Get("", list);

Use reflection. (I'm not going to show an example because it's needlessly complicated.)

Servy
  • 197,813
  • 25
  • 319
  • 428
  • I had thought about the second solution, but I didn't like the way it looked. I thought the first one would actually throw an exception, but you are correct that it wont. Thanks. – bpeikes Apr 06 '15 at 15:01