C# CLR/编译问题
我昨天发布了这个问题询问关于将 ASP.NET 应用程序部署到 .NET 3.5 目标服务器的 C# 4 客户端,以及服务器上的 C# 3 或客户端上的 C# 4 编译的内容。
该场景带有可选参数。我知道从 .NET 1.1 开始就支持可选参数。为什么 C# 3 编译的 IL 代码无法使用可选参数调用 C#4 编译的 IL 代码?
C# 3 是否只是忽略可选属性?
I posted this question yesterday asking about a C# 4 client deploying an ASP.NET application to a .NET 3.5 target server and weather C# 3 on the server compiled something or C# 4 on the client.
That scenario was with optional parameters. I know optional parameters have been supported since like .NET 1.1. Why is it that C# 3 compiled IL code is not be able to call C#4 compiled IL code using optional parameters?
Does C# 3 just ignore the optional attribute?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可选参数仅在 4.0 版本中引入到 C# 中。
(它们之前在 VB 的 .NET 中可用)。
Optional parameters were introduced to C# only in version 4.0.
(They were available in .NET earlier in VB).
你是对的......IL只是用OptionalAttributes装饰,但它是调用编译器决定做什么......
来自Richter:
所以它是 CALLING 编译器决定如何使用可选值,而不是调用的 c# 4.0 IL...
更多关于边缘情况以及如何决定值的调用方法可以从 Lippert, @ http://blogs .msdn.com/b/ericlippert/archive/2011/05/16/optional-argument-corner-cases-part- Three.aspx
You're right... The IL is just decorated w/ OptionalAttributes, but it's the calling compiler that decides what to do...
From Richter:
So it's the CALLING compiler deciding what to do w/ the optionals, not the called c# 4.0 IL...
More on edge cases and how it's the calling method that decides value can be found from Lippert, @ http://blogs.msdn.com/b/ericlippert/archive/2011/05/16/optional-argument-corner-cases-part-three.aspx
我的简单猜测是因为基类库不同?这使得 C# 3.* 和 4.* 之间的差异比 2.* 与 3.* 之间的差异大得多,因为后者使用相同的 BCL。
但不确定。
My simple guess would be because the Base Class Libraries are different? This makes the difference between C# 3.* and 4.* much bigger than say 2.* vs 3.* as the latter used the same BCL.
Not sure though.