Practice mode C#

Which of these conversions in C# requires an explicit cast?

Correct answer B. double to int

Explanation

C# allows implicit numeric conversions only when no information can be lost in magnitude, such as int to long, int to double or byte to int. Converting double to int may lose the fractional part and can overflow, so you must write (int)d. The cast truncates towards zero, so (int)3.99 gives 3 and (int)-3.99 gives -3.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.