what is the difference between Convert.ToInt16(somenumber)
and ToInt16(somenumber)
and also vs. (ToInt16)somenumber
when do we have to use one over the other?
Convert.Int16()
is a method (probably) in System.Convert
. It has a number of overloads that convert from a type to Int16
.ToInt16()
could be a method defined for a particular class, but most likely you are just referring to the exact same method. Read up on namespaces.
But if you have a class called Unicorn
and it has a ToInt16()
method, you obviously will have to use that as there is no overload in System.Convert
that supports Unicorn
.
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