Can you use optional parameters in code targeting .NET 3.5?

后端 未结 7 935
独厮守ぢ
独厮守ぢ 2020-11-30 10:46

I\'m looking to write a library that uses the new optional parameters feature of C# 4.0, but I want to target it to the 3.5 version of the framework. Is this possible?

7条回答
  •  旧时难觅i
    2020-11-30 11:43

    You can use optional and named parameters in a targeted framework of a previous version as long the assemblies are build within a development environment for v4 (f.e. VS2010). But you should be aware of runtime compiling or publishing websites in this case the compiler of the targeted framework will be used. And because the compilers of the older frameworks doesn't understand the syntax of optional and named params it will results in compiler errors.

提交回复
热议问题