2009-12-07 64 views
0

嗨,我顯示版本值從註冊表中.For從註冊表獲取值我做了以下代碼。從註冊表獲取值問題

 // Where WrmSpoAgentRoot= @"Software\syscon\Point Monitor\"; 
    string keySpoPath = SpoRegistry.WrmSpoAgentRoot; 
    RegistryKey regkey = Registry.LocalMachine.OpenSubKey(keySpoPath); 

,但我想在一個property..So我創建了一個屬性「Wrmversion」分配該值。但是,當我分配這個值,,「REGKEY」變量不 財產分配中意味着智能感知不產生「REGKEY」變量(名稱「REGKEY」在目前情況下不存在)

public string Wrmversion 
{ 
    get { return m_wrmversion; } 
    set { m_wrmversion = value; } 
} 

private string m_wrmversion = string)regkey.GetValue(
          SpoRegistry.regValue_CurrentVersion); 

有沒有辦法在財產分配值一樣

回答

1

寫這個任務裏面構造函數。

讓我們假設這個類被命名爲FooBar。你應該寫:

class FooBar 
{ 

    //other code goes here 

    public FooBar() 
    { 
     m_wrmversion = (string)regkey.GetValue(SpoRegistry.regValue_CurrentVersion); 
    } 
} 
+0

,所以我也這樣,沒有任何邏輯問題,, 公共類WindowsAgent { 公共字符串Wrmversion { 得到{m_wrmversion; } set {m_wrmversion = value; } } private string m_wrmversion = null; } public WindowsAgent() { string keySpoPath = SpoRegistry.WrmSpoAgentRoot; RegistryKey regkey = Registry.LocalMachine.OpenSubKey(keySpoPath); m_wrmversion =(string)regkey.GetValue(SpoRegistry.regValue_CurrentVersion); } // WindowsRes – peter 2009-12-07 06:37:25