Answer the question
In order to leave comments, you need to log in
Fields and Properties / get / set - what is it? How to understand? Is it possible to explain in a simpler/humane way?
https://www.youtube.com/watch?v=CSbix3v6AUY&list=P... I'm taking a course and I'm completely stuck here. Some kind of Get Set, accessor, etc. I don’t understand what and why and why? Can you explain a little more simply with a simple example? After all, someone who understands can easily give a simple example?
Answer the question
In order to leave comments, you need to log in
As I understand it, the fields and methods are already clear to you.
For example, you have a code that displays the area of a square in the console:
void Calculate()
{
var quad = new Quad();
quad.Size = 10;
Console.WriteLine(quad.Area);
}
class Quad
{
public float Size;
public float Area;
}
void Calculate()
{
var quad = new Quad();
quad.Size = 10;
quad.Area = quad.Size * quad.Size;
Console.WriteLine(quad.Area);
}
class Quad
{
public float Size;
public float Area;
public void UpdateArea()
{
Area = Size * Size;
}
}
class Quad
{
public float Size;
public float GetArea()
{
return Size * Size;
}
}
class Quad
{
public float Size;
public float Area
{
get { return Size * Size; }
}
}
class Quad
{
private float size;
public float Size
{
get { return size; }
set
{
size = value;
Area = size * size;
}
}
public float Area;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question