FAQ: Basic Classes and Objects - Fields

This community-built FAQ covers the “Fields” exercise from the lesson “Basic Classes and Objects”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise Fields

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Apologies for the poor formatting. I don’t know how to make my double enters show up.

I am having difficulty understanding how fields and objects relate to each other. I find it helpful when these concepts are related to concepts which I am already familiar with. For example, relating a field to a variable. This is done in the explanation that I took from exercise and typed out below:

"Create fields like this:

class Forest {
public string name;
public int trees;
}

This might look similar to defining a variable. It is! Each field is a variable and it will have a different value for each object."

The problem is that it seems to me that the concept of object was also related to a variable in an example and explanation from the previous exercise.

This example states that ‘phrase’, a variable, is an instance of string. To me the use of the words ‘instance of string’ suggests that phrase is an object of string.
I say this because the definition of object involves the words ‘instance of a class’ and class is contrasted to the custom data types like string.

I hope this makes sense so far. Could someone please explain why I am wrong about ‘phrase’ being an object of string.

Also, if class relates to data types, and fields relate to variables, then what are objects? The values assigned to the variables?

Thank you so much if you took the time to read this.

2 Likes

Hey, have you since posting this found some clarity on this topic? I would love to hear your insights!

No, sorry mate. I’ve been super busy the last few weeks and so I’ve put the c# learning on hold. In a few weeks I’ll have more time and I’ll update you if I work it out :slight_smile:

If you are having a hard time wrapping your mind around this I would recommend watching Brackeys’ “How to program in C# - Classes (E07)” all the way through then doing the Codecademy afterword. It really helped me.

1 Like