-3

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

4

4 回答 4

1

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.

于 2009-03-09T20:54:50.070 回答
0

This works fine:

IList<int> Foo() {
    return null;
}
于 2009-03-09T20:56:06.993 回答
0

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.

于 2009-03-09T20:57:45.133 回答
0

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.

于 2009-03-09T21:03:30.737 回答