[英]What is the difference between OptionalAttribute and optional parameters in C# 4.0
I'm researching someone else's code and there is a method like this: 我正在研究别人的代码,有一种方法是这样的:
public SomeClass DoSomething(string param1, [Optional, DefaultParameterValue("")] string optional)
Why would someone use these attributes instead of 为什么有人会使用这些属性而不是
public SomeClass DoSomething(string param1, string optional = "")
Is there any difference in the behavior, etc.? 行为等有什么不同吗?
If they weren't using C# 4, for example? 例如,如果他们没有使用C#4? I believe the second version will compile into exactly the first version... 我相信第二个版本将编译成第一个版本......
(I've compiled them both and run them through ILDASM - there were no significant differences.) (我已将它们编译并通过ILDASM运行它们 - 没有显着差异。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.