Alternative for Microsoft.VisualBasic.Information.IsNumeric in C#
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
as per the information while doing googling I did this
attrval[5] = (WrmService.WindowsAgent.AgentVersion == null || Microsoft.VisualBasic.Information.IsNumeric(WrmService.WindowsAgent.AgentVersion)) ?
"0.0.0.0" : WrmService.WindowsAgent.AgentVersion;
but Microsoft.VisualBasic.Information.IsNumeric making problems. Is there any similar one in C#?
only two outputs I requ开发者_如何学Pythonired one will be numeric and one will be any other, it can be string or null whatever it i have to set in to 0.0.0.0
Try
if(!int.TryParse(WrmService.WindowsAgent.AgentVersion, out attrval[5])) attrval[5] = 0;
In this case, if AgentVersion is numeric, it will place the parsed value into attrval[5], otherwise it will set it to 0.
edit
Ah I guess you are looking for:
attrval[5] = string.IsNullOrEmpty(WrmService.WindowsAgent.AgentVersion) ? "0.0.0.0" : WrmService.WindowsAgent.AgentVersion;
I would recomend using something like
Int32.TryParse Method (String, Int32)
See also C# Equivalent of VB's IsNumeric()
You could use Int32.TryParse() to check if it is an integer value.
精彩评论