为什么允许空对象扩展方法? [英] why allow extension methods on null objects?

查看:95
本文介绍了为什么允许空对象扩展方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是允许的对空对象的扩展方法调用的地步?
这让我不必要检查的扩展方法空对象。
AFAIK,我不明白这一点?
请解释。

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.

推荐答案

扩展方法是C#语言的语法糖,他们会被编译到普通的静态方法调用在ILCode。静态方法不知道在编译时的参数任何事情。

Extension methods are syntactic sugar of the C# language, they get compiled to normal static method calls in ILCode. A static method doesn't know anything about the parameters at compile time.

这篇关于为什么允许空对象扩展方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆