该路由寄存器语句的语法是什么
routes.Add(new Route("Catalog/{color}", new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(
new { controller = "Products", action = "List" }
)
});
我不太明白上面的语法,据我所知,它向 RouteTable.Routes 集合添加了一个新的路由对象,该 Route 对象有一个构造函数: Route(String, IRouteHandler),以及'RouteValueDictionary'类型的属性'Defaults',但是这里的语法是什么,它看起来像c# 3.0中的对象初始化表达式,但它调用了构造函数,任何人都可以解释一下吗?
非常感谢。
routes.Add(new Route("Catalog/{color}", new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(
new { controller = "Products", action = "List" }
)
});
I don't quite understand the above syntax, as far as i know, it adds a new route object to RouteTable.Routes collection, the Route object has a constructor:
Route(String, IRouteHandler), and a property 'Defaults' of 'RouteValueDictionary' type, but what's the syntax here, it looks like Object Initialization Expressions in c# 3.0, but it invokes the constructor, can anyone explain it a bit?
many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是一个对象初始化表达式,但这些表达式可以选择包含构造函数参数。通常,当您看到这些初始化表达式时,正在使用默认构造函数,在这种情况下,您不需要
new
之后的括号。It is an object initialization expression, but those expressions can optionally include constructor parameters. Typically, when you see those initialization expressions, the default constructor is being used, in which case you don't need the parens after the
new
.