tags:

views:

33

answers:

1

Hi i am displaying version value from registry .For fetching value from registry i did the following code.

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

But i want to assign this value in to a property..So i created a property "Wrmversion".But when i am assigning this value ,,'regkey' variable is not assigning in to the property means intellisense is not producing 'regkey' variable(The name 'regkey' does not exist in the current context)

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

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

Is there any way to assign value in to property like

+1  A: 

Write this assignment inside a constructor.

Let's suppose this class is named FooBar. You should write:

class FooBar
{

    //other code goes here

    public FooBar()
    {
        m_wrmversion = (string)regkey.GetValue(SpoRegistry.regValue_CurrentVersion);
    }
}
qbeuek
so i did this way,is there any logical problem,, public class WindowsAgent { public string Wrmversion { get { return 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