开发者

What's the syntax of this route register statement

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 o开发者_如何学JAVAbject 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜