How can tell if my object's value is a float or int?
For example, I would like this to return me bool value.
I'm assuming you mean something along the lines of...
if (value is int) {
//...
}
if (value is float) {
//...
}
Are you getting the value in string form? If so there is no way to unambiguously tell which one it isbecause there are certain numbers that can be represented by both types (quite a few in fact). But it is possible to tell if it's one or the other.
public bool IsFloatOrInt(string value) {
int intValue;
float floatValue;
return Int32.TryParse(value, out intValue) || float.TryParse(value, out floatValue);
}
if (value.GetType() == typeof(int)) {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With