C#中Microsoft.VisualBasic.Information.IsNumeric的替代方案

时间:2010-01-13 10:50:12

标签: c#

attrval[5] = WrmService.WindowsAgent.AgentVersion;

从上面如果attrval [5]为null或者没有得到任何值或除数值之外的任何字符串我想将attrval [5]赋值为'0.0.0.0',否则我会 显示即将到来的数值。我必须在这里实现什么编码

根据谷歌搜索时的信息,我做了这个

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

但是Microsoft.VisualBasic.Information.IsNumeric出现问题。 C#中有类似的吗?

我只需要两个输出,一个是数字,一个是任何其他输出,它可以是字符串或null,无论我必须设置为0.0.0.0

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

尝试

if(!int.TryParse(WrmService.WindowsAgent.AgentVersion, out attrval[5])) attrval[5] = 0;

在这种情况下,如果AgentVersion是数字,它会将解析后的值放入attrval [5],否则会将其设置为0。

修改

啊我想你在寻找:

attrval[5] = string.IsNullOrEmpty(WrmService.WindowsAgent.AgentVersion) ? "0.0.0.0" : WrmService.WindowsAgent.AgentVersion;

答案 2 :(得分:0)

您可以使用Int32.TryParse()来检查它是否为整数值。