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.? 回答1: If they weren't using C# 4, for example? I believe the second version will compile into exactly the first version... (I've compiled them both and run them