Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C#

Aaron Selonke
Aaron Selonke
10,323 Points

defining a field in the IDE

I'm following this in Visual Studio's instead of Workspaces.

I learned from Mike Tabor that defining a field in a class should be done in the IDE with prop + TAB TAB

which creates the class field template that looks like this: public int MyProperty { get; set; }

What's the difference between stating a field this way? What do the get and set statements mean?

4 Answers

Check out this SO post What is the { get; set; } syntax in C#, the first two answers should cover what you are looking for.

Shadi Abdelsalam
Shadi Abdelsalam
9,490 Points

It automaticly creates a constructor and a method,which return a field's value

Glen Hayes
Glen Hayes
5,798 Points

The get and set fields are essentially methods to either return a methods value (get) or input another value ie (set) the value. Its just shorthand.

I also use Visual Studio instead of the workspaces because it seems to offer a lot more functionality, but havnt used the prop + TAB TAB thingy.

As I learn I much prefer to constantly type full methods and classes out by "finger" so it "sinks" in better.

Aaron Selonke
Aaron Selonke
10,323 Points

Yes, the IDE seems like one of the best advantages of C# Also noticed that it is more strict with using the static modifier than the mono compiler Thanks