ASP.NET: URI handling

后端 未结 6 2103
暗喜
暗喜 2021-01-06 05:53

I\'m writing a method which, let\'s say, given 1 and hello should return http://something.com/?something=1&hello=en.

I

6条回答
  •  独厮守ぢ
    2021-01-06 06:29

    Here's my version (needs .NET4 or a ToArray() call on the Select)

    var items = new Dictionary { { "Name", "Will" }, { "Age", "99" }};
    
    String query = String.Join("&", items.Select(i => String.Concat(i.Key, "=", i.Value)));
    

    I thought the use of Dictionary might mean the items can get reordered, but that doesn't actually seem to be happening in experiments here - not sure what that's about.

提交回复
热议问题