Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Perfect Integers and Doubles

Andre Kucharzyk
Andre Kucharzyk
4,479 Points

Why C# can compile "int x = 8 / 3", but refuses to compile "int x = 2.9"

Why C# can compile "int x = 8 / 3", but refuses to compile "int x = 2.9"

2 Answers

Stuart Wright
Stuart Wright
41,119 Points

Because in C#, if you divide an integer by an integer, you will get an integer back. 9 / 3 would be 3 as per normal division. 8 / 3 results in 2. It rounds down to the nearest integer.

Andre Kucharzyk
Andre Kucharzyk
4,479 Points

Thanks for clear and fast answer Stuart. What a cool name