开发者

Path change for achieving the functionality

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

开发者_JAVA百科
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


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 + "\\";


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜