I have a sql datareader…From which I have to fetch one decimal value.
What is the difference between
- (decimal)datareader[“percent”]
and
- Convert.Todecimal(datareader[“percent”])
And what are prons and cos ….of both methods.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Casting will succeed only if the object returned by
datareader["percent"]is of the typeDecimal. Conversion will succeed when the object is of any type convertible toDecimal. This includesint,long,short, etc. Or more generally, anything that implementsIConvertibleand returns a useful value fromIConvertible.ToDecimal()can be passed toConvert.ToDecimal().For example: