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#

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