2010-01-27 62 views
0

我必須從註冊表獲取版本值,路徑爲HKEY_LOCAL_MACHINE\SOFTWARE\Secon\Secon Monitor。在該路徑中,我們可以看到一個包含價值的文件CurrentVersion實現功能的路徑更改

所以我做了這個類型的編碼來獲取價值的

有一個類文件Simregistry.cs所有的註冊表路徑是registered.So我有一個註冊的路徑如下

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

然後我訪問'SimRoot'這對diferrent文件

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

但我需要實現相同的功能這樣。我需要用這種方式來註冊路徑

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

代替:

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

我怎樣才能改變這種代碼

string keySpoPath = SpoRegistry.SimRoot; 
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(keySpoPath); 
m_version = (string)regkey.GetValue(SpoRegistry.regValue_CurrentVersion); 
實現這一目標

我可以像這樣添加@ SpoRegistry.SimRoot + @ ,,但是我怎樣才能刪除這兩個額外的斜槓()後軟件和後一個Secon

+0

究竟是什麼問題?爲什麼你需要讓字符串逃脫? – James 2010-01-27 10:29:19

+0

我需要更改公共常量字符串SimRoot = @「Software \ Secon \ Secon Monitor」;公共常量字符串SimRoot =「Software \\ Secon \\ Secon Monitor \\」; 所以我在這裏做什麼改變string keySpoPath = SpoRegistry.SimRoot; RegistryKey regkey = Registry.LocalMachine.OpenSubKey(keySpoPath); m_version =(string)regkey.GetValue(SpoRegistry.regValue_CurrentVersion); 實現相同的功能 – peter 2010-01-27 10:38:08

+0

可以添加@像這樣SpoRegistry.SimRoot + @ ,,但我怎麼能刪除這兩個額外的斜線(\\)一個後軟件和一個後Secon – peter 2010-01-27 10:47:25

回答

0

串之間的唯一區別:

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

和:

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

是第一個具有結尾斜槓(\)。

你可以簡單地把它串聯到您的常數:

string keySpoPath = SpoRegistry.SimRoot + "\\"; 
+0

我的意圖是使代碼更改,在此我需要改變公共常量字符串的方式SimRoot = @「Software \ Secon \ Secon Monitor」;公共常量字符串SimRoot =「Software \\ Secon \\ Secon Monitor \\」; ,,所以我怎樣才能改變代碼 – peter 2010-01-27 10:35:48

+0

沒有@符號和這個符號(\\)是更多的兩面,我怎麼能削減 – peter 2010-01-27 10:39:28

+0

你應該找出更多關於'@'做什麼。@「\」和「\\」是C#中相同的字符串 – Oded 2010-01-27 10:42:46

0

無需添加任何東西。兩者都是相同的公共常量字符串SimRoot =「Software \ Secon \ Secon Monitor \」;和公共常量字符串SimRoot = @「Software \ Secon \ Secon Monitor」; 是一樣的

+0

這將給我的問題http://en.csharp-online.net/CSharp_String_Theory%E2%80%94String_literals – peter 2010-01-27 16:37:14