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 trialIgnacio Uriz
5,042 PointsC# Variables Questions
The teachear in the c# course has told me to create a variable like this e.g string example; Is there any other way? Because I know javascript, so is strange to see this new way of creating variables.I tried this var example; and it work so what should I used?
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! As I understand it the big difference between var and explicitly stating the type is that the compiler will determine the data type stored in the var
upon compilation. JavaScript is an untyped language. C# is strongly typed. That being said, there are other languages that are also "strongly-typed" such as Java, Objective C etc.
I think in this case it comes down to personal preference. I prefer to explicitly state the type of data that should go into that variable so as to avoid ambiguity when debugging my code later on down the road. But again, this is my personal preference.
However, there are instances when an "anonymous" type is required. At that point, you will have to use var. I believe you're still a ways off from that at this point, though.
That being said: here is documentation from MSDN about using var
.
Hope this helps!
Ignacio Uriz
5,042 PointsThank you for your response!