I have a question regarding fields and properties. I am stuck regarding one matter and that is when it comes to Constructors. We took how the convention of naming Properties is with title-casing. So if the field is ‘age’ then the Property will be ‘Age’. Then when it came to the Constructors section of CodeAcademys Learning C#, we took that when creating a Constructor you Initialize the Field before then you set it in the body of the Constructor. This is the example code in the lesson:
class Forest
{
public int Area;
public Forest(int area)
{
Area = area;
}
}
Here is where my problem comes…
If we are saying that the Field is going to be lowercased then why does it say in the lesson, “We can add code in the constructor to set values to fields:” How are we setting a field if the naming convention is of that which indicates it to be Property? Also where is the Field for the Area property?
I hope someone can help me. Thanks!
I tried to see find the difference between the fields and properties in Constructors but haven't seemed to have found a clear answer.