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 trialXiaolong Yang
4,374 PointsWhy not adding a semicolon after Content = "XXX"?
After copy and paste the "Hello from the comic books control" to the ContentResult(), why not have a semicolon after it? and why is there a semicolon after the curly braces?
2 Answers
Steven Parker
231,198 PointsGenerally, semicolons only go after statements.
The braces after new ContentResult() enclose a list of initial object properties, and since there is only one no punctuation is needed. If the list had included additional properties, they would have been separated by commas.
The entire expression is part of a return statement, so after the closing brace a semicolon is used to indicate the end of that statement.
Edward Ries
7,388 PointsJust in case your still struggling with this one. ContentResult("XXX", "YYY") would be passing values into the constructor for the ContentResult class and ContentResult() {Content = "XXX", ContentEncoding = "YYY"} is assigning values to the properties of the ContentResult. As Steven mentioned you were setting multiple properties then they are comma separated but if there's only 1 value being set then you can skip the comma.
Xiaolong Yang
4,374 PointsThank you ~~ got it~~
Xiaolong Yang
4,374 PointsXiaolong Yang
4,374 PointsThanks for your help, I got why there is a semicolon after the brace of return, but I'm still a little confused about why there is no semicolon after Content = "Hello from the comic books controller"... is it like declaring something in this way? : ContentResult a = new ContentResult("Hello from the comic books controller")? I could write ContentResult() {Content = "XXX", ContentEncoding = "YYY"} just like something like ContentResult("XXX", "YYY")?