ASP.NET MVC DefaultValue 属性与 C# 可选参数
之间有什么区别
public ActionResult DoStuff([DefaultValue(MyEnum.Alpha)] MyEnum enumToUse, bool printPage = false)
{
//...
}
使用 DefaultValue 属性的 ASP.NET MVC2 方法签名与使用 C# 4.0 可选参数的签名
public ActionResult DoStuff(MyEnum enumToUse = MyEnum.Alpha, bool printPage = false)
{
//...
}
?这两种说法在功能上是否有所不同,或者只是偏好问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
都是一样的,看个人喜好了。我会使用第二个,因为它的击键次数更少。另外,我认为
DefaultValueAttribute
将涉及一些反射巫术,因此如果您对性能很敏感,您可能更喜欢 C# 4.0 可选参数。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.