public string AgentVersion
{
get { return m_version; }
} // property: Enabled
private string m_version = null;
The below declaration coding i did in Constructor
string keySpoPath = SpoRegistry.SpoAgentRoot;
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(keySpoPath);
m_version = (string)regkey.GetValue(SpoRegistry.regValue_CurrentVersion);
here are my doubts
-
Do I need
private string m_version = null;in property declaration in this context? If I remove that one, are there any probs? -
If
AgentVersionisnullor not getting any value or any strings other than numeric values I want to assign AgentVersion to value ‘0.0.0.0’ otherwise i will
display the numeric value which is coming. Is this code below sufficient here
string.IsNullOrEmpty(AgentVersion) ? "0.0.0.0" : AgentVersion;If then where and how can I implement in ‘Property’
1) You don’t need to instantiate
m_versionas null in this context. You usually only need to do this when declaring a local variable, to avoid the ‘Use of unassigned local variable [name]‘ compile error. Soprivate string m_version;will suffice.2) For checking null and empty values, what you have with
String.IsNullOrEmpty()is fine. If you want to go check your property returns strings in the correct format, you can useRegex.IsMatch()to ensure the property only ever returns strings in version number-format.My regular expressions are a bit rusty, so someone can probably improve on what I have here, but it’s the general gist of what you need.