views:

512

answers:

4

Why can an IEnumerable = null be passed without error but an IList=Null will not compile?

+1  A: 

That's not true. You can set a variable of type IEnumerable or IList to a null reference and it will compile.

There is something else in your code that is wrong.

casperOne
A: 

This works fine:

IList<int> Foo() {
    return null;
}
Sam Saffron
A: 

It's hard to know exactly what you mean. You say a null reference for an IEnumerable can be 'passed without error'. 'Passing' is a runtime thing, but you say with an IList you get a compile error? That sounds confused. You'll need to give us some more info.

Tor Haugen
A: 

Well, with your exact question, it could be because C# is case-sensitive - null is a literal, but Null isn't. It's hard to say given that you haven't posted any code which could actually compile though.

If that's not the problem in your real code, post your real code and we'll see what we can do.

Jon Skeet