Storing strings in dictionary  
Author Message
Ritesh Tijoriwala





PostPosted: Visual C# General, Storing strings in dictionary Top

Hi,

I have the following situation:

\\abc\\xyz" if I hover mouse during debug

\\mypath\\map" if I hover mouse during debug

Dictionary<string, string> d = new Dictionary<string, string>();

d.Add(s, t);

// Now if I view the content of dictionary during debug, I have strings stored as:

// "\abc\xyz" and "\mypath\map" so that when I do:

string r;

r = dSleep; // fails right here to retrieve value because dictionary stores it with single backslash and s has double

How do I make this work

Thanks,




Visual C#7  
 
 
littleguru





PostPosted: Visual C# General, Storing strings in dictionary Top

I have tested your code and works fine for me. The double backslashes you see, when hovering s or t, are only the escape codes for the \. The \ is used in C# strings to enter special characters, such as \n (for new line), \t (for tabs) or \" (for quotes). If you want to enter a backslash you have to escape that too, which leads into \\.

The dictionary is only showing the string without the escape codes!



 
 
Ritesh Tijoriwala





PostPosted: Visual C# General, Storing strings in dictionary Top

Hi littleguru,
I also retested my code and it worked just fine. I was mixing the fact that the strings are stored internally as single slash but are displayed in de**** as double slash (with the escaped character if any).

Thanks for the reply...