tags:

views:

23

answers:

2

I have to get version value from registry, the path is HKEY_LOCAL_MACHINE\SOFTWARE\Secon\Secon Monitor. In that path we can see one file CurrentVersion which contain value.

So i did this type of coding to fetch value

There is one class file Simregistry.cs where all registry paths are registered.So there i registered one path as below

public const string SimRoot = @"Software\Secon\Secon Monitor";

then i accessed 'SimRoot' this on diferrent file

string keySpoPath = SpoRegistry.SimRoot;
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(keySpoPath);
m_version = (string)regkey.GetValue(SpoRegistry.regValue_CurrentVersion);

But i need to achieve the same functionality this way .i need to register path in this way

public const string SimRoot = "Software\\Secon\\Secon Monitor\\"; 

instead of:

public const string SimRoot = @"Software\Secon\Secon Monitor";`

how can i achieve this by changing this code

string keySpoPath = SpoRegistry.SimRoot;
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(keySpoPath);
m_version = (string)regkey.GetValue(SpoRegistry.regValue_CurrentVersion);

i can add @ like this SpoRegistry.SimRoot+ @,,but how can i remove those two extra slashes() one after Software and one after Secon

A: 

The only difference between the strings:

public const string SimRoot = "Software\\Secon\\Secon Monitor\\"; 

And:

public const string SimRoot = @"Software\Secon\Secon Monitor";

Is that the first has a trailing slash (\).

You can simply concatenate it to your constant:

string keySpoPath = SpoRegistry.SimRoot + "\\";
Oded
what my intention is make the code changes ,in this way that i need to change public const string SimRoot = @"Software\Secon\Secon Monitor"; to public const string SimRoot = "Software\\Secon\\Secon Monitor\\"; ,,so how can i change the code
peter
no @ symbol and this symbol (\) is more in two sides,,how can i cut
peter
You should find out more about what the `@` does. @"\" and "\\" are the same string in C#
Oded
can add @ like this SpoRegistry.SimRoot+ @,,but how can i remove those two extra slashes(\) one after Software and one after Secon
peter
Again - you don't need to. In a regular string, the `\\` are evaluated as a `\` (this is called string escaping - look it up). In a string literal (one that has a `@` in front of it), you don't need to escape the `\`.
Oded
thats right,,thanks
peter
A: 

No need to add anything more. both are same public const string SimRoot = "Software\Secon\Secon Monitor\"; and public const string SimRoot = @"Software\Secon\Secon Monitor"; are same

peter
this will give the information regarding my question http://en.csharp-online.net/CSharp_String_Theory%E2%80%94String_literals
peter