[英]Using concatenated verbatim strings as keys in C# NameValueCollection
I have been trying to use verbatim strings to create a string that I will be using as a key to reference value in a NameValueCollection. 我一直在尝试使用逐字字符串创建一个字符串,该字符串将用作键来引用NameValueCollection中的值。
The string I want is this \\\\storage\\local
So I create a verbatim string 我想要的字符串是这个
\\\\storage\\local
所以我创建了一个逐字字符串
string key = @"\\storage\local";
Later I use it as a key in on a NameValue collection Like this 后来我将其用作NameValue集合上的键,像这样
string value = Settings[key];
When I debug the above code and look at the key, it shows \\\\\\\\storage\\\\local
with the escape sequence format. 当我调试上面的代码并查看密钥时,它以转义序列格式显示
\\\\\\\\storage\\\\local
。 Since this is not the key that is in my settings, I am not getting a value. 由于这不是设置中的关键,因此我没有任何价值。 Please help me understand how I can use the
\\\\storage\\local
as the key on my collection. 请帮助我了解如何使用
\\\\storage\\local
作为集合上的密钥。
The \\\\\\\\ is just a debugger representation (with escaped backslashes). \\\\\\\\只是调试器的表示形式(带有转义的反斜杠)。 This is the expected behaviour.
这是预期的行为。 You can test it works by using the following sample:
您可以通过使用以下示例来测试它是否有效:
string value = "Some value";
Settings[@"\\storage\local"] = value;
string value1 = Settings[@"\\storage\local"];
string value2 = Settings["\\\\storage\\local"];
Both value1 and value2 will have the same result which is "Some value" value1和value2都将具有相同的结果,即“某些值”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.