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,495
  • 9
  • 42
  • 80

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
  • 202,030
  • 26
  • 332
  • 449
  • 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