1

What is the difference between this ASP.NET MVC2 method signature, which uses the DefaultValue attribute:

public ActionResult DoStuff([DefaultValue(MyEnum.Alpha)] MyEnum enumToUse, bool printPage = false)
{
    //...
}

And this signature, which instead uses a C# 4.0 optional argument?

public ActionResult DoStuff(MyEnum enumToUse = MyEnum.Alpha, bool printPage = false)
{
    //...
}

Are the two statements different in any functional way, or is it just a matter of preference?

1 Answer 1

4

Same stuff, it's a matter of personal preference. I would use the second as it's less keystrokes. Also I think that the DefaultValueAttribute will involve some reflection voodoo so if you are anal about performance you might prefer the C# 4.0 optional arguments.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.