在 C# 中输出操纵的 QueryString [英] Outputting a manipulated QueryString in C#

查看:20
本文介绍了在 C# 中输出操纵的 QueryString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码,我得到了一个漂亮的格式化字符串:

Using the following code I get a nice formatted string:

Request.QueryString.ToString 

给我类似的东西:&hello=world&microsoft=sucks

Gives me something like: &hello=world&microsoft=sucks

但是,当我使用此代码将集合克隆到另一个对象(相同类型)时,我反而从 ToString() 方法中获取了 Type().

But when I use this code to clone the collection to another object (of the same type) I get the Type() back from the ToString() method instead.

System.Collections.Specialized.NameValueCollection variables = new System.Collections.Specialized.NameValueCollection(Request.QueryString);
if (!string.IsNullOrEmpty(variables["sid"]))
    variables.Remove("sid");
Response.Write(variables.ToString());

有没有比手动查找和构建字符串更简洁的输出方式?

Is there a tidier way to output it rather than looking and building the string manually?

推荐答案

您也可以使用 Reflector 将 HttpValueCollection 类提取到您自己的类中,然后使用它.

You can also use Reflector to extract the HttpValueCollection class into your own, and use it then.

这篇关于在 C# 中输出操纵的 QueryString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆