why allow extension methods on null objects?

2019-04-18 15:15发布

what is the point of allowing invocation of extension methods on null objects? this is making me unnecessarily check for a null object in the extension method. AFAIK,i can't understand this? Please explain.

7条回答
Evening l夕情丶
2楼-- · 2019-04-18 16:03

Extension methods are just syntactic sugar. In reality they are static methods on another class, so since you can write

IEnumerable<int> foo = null;
Enumerable.Count(foo);

You can also write

IEnumerable<int> foo = null;
foo.Count();
查看更多
登录 后发表回答