Whats the difference between Cast & Convert in C# 2008?
Share
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.
Cast will allow you to convert certain data types safely, eg. double-> int
Here cast is taking the binary representation of 3.5 and putting it into integer representation. Because integer doesn’t have fractions it is dropped and also allowed. Casting a string to an integer in this way is not so simple and not allowed by the compiler.
Convert is smarter and convert more data types from one to another, eg. string -> boolean
Also see this stackoverflow discussion on this topic.