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# C# Objects Loops and Final Touches Foreach Loops

Jose Perez
Jose Perez
1,338 Points

Really need help fully understanding general concept!!!! Kind lost

I have watch almost all videos, but I don’t seem to understand why we need to create an object? And how do I know when I need to create it?

I don’t quite understand what is a field and encapsulation?

Can someone please help me, if you can give some small example I can run and test it will be very helpfully as well.

Thank you.

1 Answer

Jose,

Jeremy uses an example of a cookie cutter to explain classes and objects. Classes are a blueprint that allow us to create objects. Classes are just patterns with attributes called fields that describe the pattern. We can't really do anything with a pattern except create something with it. That something is called an object.

Going back to the cookie cutter; we know what shape it should be, but the only thing you can do with it is stamp out the shape into the cookie dough. Once we've created that object out of cookie dough, then we can do stuff with it, like throw it into the oven. The fields could be the color of the dough, or how think/ thing the dough has been rolled out; all attributes of the now stamped out cookie.