可选参数code编译在.NET 3.5。为什么? [英] Optional Argument code compiles in .NET 3.5. Why?

查看:268
本文介绍了可选参数code编译在.NET 3.5。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一块code编译一个框架3.5的项目在VS 2010中确定(我三重检查了)

This piece of code compiles OK in VS 2010 in a framework 3.5 project (I triple checked that)

    public LoggingClient(string uri = "net.msmq://localhost/logging"){...}

为什么呢?我什么也看不到在C#4规格(<一href="http://download.microsoft.com/download/7/E/6/7E6A548C-9C20-4C80-B3B8-860FAF20887A/CSharp%204.0%20Specification.doc">doc版本),第21.1节,是说,这应该是向后兼容。它怎么说,我没有得到任何编译错误?这是否会在某些情况下静默失败?

Why? I see nothing in the C# 4 spec (doc version), section 21.1, that says this should be backwardly compatible. How is it that I get no compilation error? Will this fail silently in some circumstances?

推荐答案

项目+属性,生成选项卡,向下滚动,高级。您可以更改语言版本为C#3.0,如果你preFER保持源$ C ​​$ C兼容性。

Project + Properties, Build tab, scroll down, Advanced. You can change the Language Version to "C# 3.0" if you prefer to maintain source code compatibility.

但是,是的,你使用的是C#4.0编译器在VS2010,无论你使用的目标.NET版本。编译器,IL的输出,并没有改变在.NET 4.0中。不,你不能使用的动态的,它需要一个.NET 4.0只支持组件(Microsoft.CSharp.dll)

But yes, you are using the C# 4.0 compiler in VS2010, regardless of the target .NET version you use. The output of the compiler, IL, hasn't changed in .NET 4.0. No, you can't use dynamic, it requires a .NET 4.0 only support assembly (Microsoft.CSharp.dll)

这篇关于可选参数code编译在.NET 3.5。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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