I just wonder how to write a number that has to be expressed as string.
For instance:
if (SelectedItem.Value == 0.ToString()) ...
or
if (SelectedItem.Value == "0") ...
or
public const string ZeroNumber = "0";
if (SelectedItem.Value == _zeroNumber) ...
or
if (Int.Parse(SelectedItem.Value) == 0)
For a single test, I'd personally go with
if (SelectedItem.Value == "0")
It has no fuss, no ceremony - it says exactly what you're trying to do.
On the other hand, if I have a value which should be a number, and then I'll react based on that number, I'd use:
int value;
// Possibly use the invariant culture here; it depends on the situation
if (!int.TryParse(SelectedItem.Value, out value))
{
// Throw exception or whatever
}
// Now do everything with the number directly instead of the string
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