Aggregate on dictionary question

China☆狼群 提交于 2019-12-12 05:13:55

问题


I am using ASP.NET MVC2 and I would like to make up a url based on the current one in the address bar inside a HtmlHelper extension. So far I have this:

url = helper.ViewContext.RequestContext.RouteData.Values
      .Aggregate<KeyValuePair<String, Object>>((w, next) => w +  next);

But that does not compile. Anyone has a good idea on how to solve this Aggregate function?


回答1:


Use this:

helper.ViewContext.RequestContext.RouteData.Values
                .Select(x => x.Value.ToString())
                .Aggregate((c, next) => c + next);

But since you want something like a url I suggest you use this:

helper.ViewContext.RequestContext.RouteData.Values
                .Select(x => x.Value.ToString())
                .Aggregate((c, next) => c + "/" + next);

Grz, Kris.



来源:https://stackoverflow.com/questions/3091705/aggregate-on-dictionary-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!