Im preparing for a very tricky c# exam and this question popped up while doing so.
I have the following code:
uint zzz = -12u;
-12u is recognized as System.Uint32 literal but it can only be stored in variable of type long. Why is that ?
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.
What it is doing is taking the unsigned int 12 and trying to convert it into a negative value (the
-) which requires a conversion to a type that can handle negative numbers as an unsigned int cannot.Because it is an unsigned int it has possible values outside the range of int, so conversion to a long is required.