English 中文(简体)
核计价核对
原标题:Null value checking
  • 时间:2010-01-13 10:12:50
  •  标签:
  • c#
  • .net

i 有一个问题

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 正在这样做,如下文所示。

if(Data.AgentVersion ==null)
                         SubItems.Add(ResourcePolicySystemsLVI.m_nullVersion);
 else
                     SubItems.Add(((IResourcePolicy)Data).AgentVersion);

如果(Data.AgentVersion ==null)到(Data.AgentVersion) =0.0.0.0

问题回答

与<代码>null的比较,与无价值的某些数值相比较,并非相同。 如果你再次提出要求,那么你必须单独检查。

然而,我对<代码>Wrmservice没有足够了解,以表示是否可能有任何无效价值。

回答您的基本问题0.0.0.0<>/code>并不等于null

你们的检验应是:

if (Data.AgentVersion == null || Data.AgentVersion.Equals("0.0.0.0")

缩略语

您不妨按照<代码>的同样思路执行一些事项。 页: 1

您可以尝试这样做,以便检查一个或几个方面:

attrval[5] = (WrmService.WindowsAgent.AgentVersion == null || Microsoft.VisualBasic.Information.IsNumeric(WrmService.WindowsAgent.AgentVersion)) ? "0.0.0.0" : WrmService.WindowsAgent.AgentVersion;

或者,如果它只是一次无效的检查,你可以尝试:

attrval[5] = WrmService.WindowsAgent.AgentVersion ?? "0.0.0.0";





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...