string concatenation problem
Please how this string concatenation taking place? i am really confuse what is happening why that slash i there and how the double quotes are used
SessionStateItemCollection items = new SessionStateItemCollection();
items["LastName"] = "Wilson";
items["FirstName"] = "Dan";
foreach (string s in items.Keys)
Response.Write("items[\"" + s + "\"] = " + items[s].ToString() + "<br />");
//here i am looking for explanation please elaborate me on this please
Response.Write("items[\"" + s + "\"] = " + items[s].开发者_运维百科ToString() + "<br />");
Only the \"
(doubles quotes immed after the backslash) is escaped.
The slash is escaping the quote. Basically it is going to write the name in quotes inside brackets. For your example the output would be:
items["Wilson"] = Wilson<br />
The escaping happens for the character directly after the backslash \
. So \"
is escaped to "
. The following "
is stopping the string and you are appending the s
variable which in turn is the current item in the foreach loop.
Here is a article on escape characters.
The backslash escapes the "
. This tells the compiler that you just want a literal double-quote, rather than ending the string literal.
精彩评论