Null value checking
i have one issue
attrval[5] = WrmService.WindowsAgent.AgentVersion;
From above if attrval[5] is null or not getting any value or any strings other than numeric values i want to assign attrval[5] to value '0.0.0.0' otherwise i will display the numeric value which is coming.What coding i have to implement here
and finally at UI there are two possible chances one is value is 0.0.0.0 or numeric value. if it is 0.0.0.0 i will display 'Unknown' string from resource file or i will display the numeric value in LISTVIEW
i am doing that one like shown below
if(Data.AgentVersion ==null)
SubItems.Add(ResourcePolicySystemsLVI.m_nullVersion);
else
SubItems.Add(((IResourcePolicy)Data).AgentVersion);
Is this sufficient means Is 0.0.0.0 is equal to null or i want to change if(Data.AgentVersion ==null) to if(Data.AgentVersion ==0.0.开发者_运维问答0.0)
Comparison with null
and comparison with a certain value which represents no value are not the same thing. If that's all you're asking, then you have to check for both separately.
However I don't know enough about the WrmService
to say if a null value is ever possible.
To answer your basic question 0.0.0.0
is not equivalent to null
.
Your test should be:
if (Data.AgentVersion == null || Data.AgentVersion.Equals("0.0.0.0")
assuming Data.AgentVersion
is a string.
You might want to implement something along the same lines as String.IsNullOrEmpty
which you can call where ever you need to do this test.
You could try this to check for a null or a number:
attrval[5] = (WrmService.WindowsAgent.AgentVersion == null || Microsoft.VisualBasic.Information.IsNumeric(WrmService.WindowsAgent.AgentVersion)) ? "0.0.0.0" : WrmService.WindowsAgent.AgentVersion;
Or if its just a null check you could try this:
attrval[5] = WrmService.WindowsAgent.AgentVersion ?? "0.0.0.0";
精彩评论