Dictionary的初始化:
Dictionaryxx = new Dictionary { { "a", 1 }, { "b", 2 } };
List的初始化:
List yy = new List { 1, 2, 3, 4 };
不用一个一个的Add,可以直接用这样的格式初始化IDictionary(?)和IList(?)的对象。
下面的RouteValueDictionary也是继承IDictionary<string,object>的,也可以用上面的格式,直接初始化值:
new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" } }
添加一个Route:
routes.Add("MyRoute", new Route("{controller}/{action}/{newid}" , new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" } } , null , new RouteValueDictionary { { "area", "Test" } } , new MvcRouteHandler()) );