If i have some code like the following:
short myShortA = 54;
short myShortB = 12;
short myShortC = (short)(myShortA - myShortB);
Both operands are shorts and it’s going into a short so why do i have to cast it?
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.
Because there’s no “short – short” operator. Both operands are promoted to int.
From section 7.7.5 of the C# 3 spec:
(And then there’s floating point subtraction.)