Reputation: 335
I am having a bit of trouble using an if statement to detect if my numericupdown object is a string so I don't use a decimal variable to adjust it. I saw there was a type of commmand, but I am having trouble using it. Here is what I am looking at:
if(typeof sentNUD.Value == string)
{
//Do string arguments here
}
else
{
//do decimal arguments here
}
The syntax of the if statement is wrong though and I get an error. How do I set up that if statement correctly? I tried looking around a bit, but I am having trouble understanding how to do this correctly. Thank you.
Upvotes: 3
Views: 255
Reputation: 414
Should you use the method's static overloading to work your solution ??
The use of "typeOf" is normaly frowned by OO purists.
Upvotes: 0
Reputation: 5689
if (sentNUD.Value.GetType() == typeof(string))
{
// string stuff
}
Upvotes: 7