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 trialRobert Patterson
2,915 PointsCan the constructor be a lamda statment too?
// can this
public Invader(Path path) { _path = path; }
// be written as
public Invader(Path path) => _path = path;
1 Answer
Steven Parker
231,248 PointsThat wouldn't technically be a "lambda" because it's not being passed as an argument. But you may be able to use an arrow definition with braces. Without braces, a return value is implied, and constructors don't return anything.
Give it a try, and let us know if it works!
Robert Patterson
2,915 PointsRobert Patterson
2,915 PointsNope! get a compiler error, that is ok though, the first way is fine
Steven Parker
231,248 PointsSteven Parker
231,248 PointsEven if it did work, using it with the brackets would be more verbose than the typical format.