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 var

problem

hi

CodeChallenge.cs
string input = "22";

var converted = int.Parse(input);

bool wheelsAreRound = true;

string downcased = "DoNuTs".ToLower();

bool success = (downcased == "donuts");

double total = 0;

3 Answers

The challenge basically asks you to replace each type name with var. You have only done that with the variable 'converted'. Just make sure that each initialization really sets the var to what's expected by the current type names.

double should be,

double total = 0.0;

You need the fractional point to make it double. Otherwise its just an integer!

Not really. In your example it doesn't matter if you input 0 or 0.0 since the left side of the equal sign already states that the variable is of type double. However if declaring the variable using var you are correct.

double total = 0; // total will be a double since it is explicitly declared as a double.
var total = 0; // total will be of type int since right side is an int.
var total = 0.0; // total will be of type double since right side is a double.

The last one is the correct answer in this challenge.

You are correct if you use VS or CMD Mono but the test engine expect answers in a specific way. You need to provide them in that order to get through the challenges.