开发者

What's the syntax of this route register statement

开发者 https://www.devze.com 2023-02-15 11:21 出处:网络
routes.Add(new Route(\"Catalog/{color}\", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(
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

精彩评论

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