2009-12-07 120 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