+ 7

Wrong answer in C# quizz

I think we have a new quizz in C# with wrong answer: What is the difference between these two ways of conversion? A) Convert.ToInt32(3.7) B) (int) 3.7 The answer accepted as correct is: A rounds to 3, while B rounds to 4. But if I'm not mistaken, A rounds to 4, B just cuts the remainder (no rounding), so B casts to 3. What do you think dear sololearners?

7th Jun 2017, 4:20 PM
Aibek T.
Aibek T. - avatar
5 Answers
+ 4
I agree. Convert.int32 uses rounding to convert. (int) just removes the remainder. A ==4. B ==3
7th Jun 2017, 6:28 PM
sneeze
sneeze - avatar
+ 5
Great news! The answer for the quizz was corrected!
14th Jun 2017, 4:18 AM
Aibek T.
Aibek T. - avatar
+ 3
@Sima : Yes that is true.
8th Jun 2017, 10:07 PM
sneeze
sneeze - avatar
+ 2
I found wrong answers with every weapon I experienced yet, but I think it's because everyone can make their own quizzes
7th Jun 2017, 4:44 PM
Arthur Fibich
Arthur Fibich - avatar
+ 2
You are right. A == 4, while B == 3. So Convert.ToInt32 method (in C# we call all functions methods, right?) rounds, while (int) just truncates decimal part of a number
8th Jun 2017, 8:44 AM
pafthinder
pafthinder - avatar