I am a bit confused with a concept of value types as properties in a class. As far as I understand, when getter is called - a copy of value type is returned. Let's have an example:
public struct Point
{
public int X;
public int Y;
public void Set(int x, int y)
{
X = x;
Y = y;
}
}
public class Test
{
public Int32 X { get; set; }
public void SetX(int x) => X = x;
public Point Point { get; set; }
}
static void Main(string[] args)
{
var test = new Test();
test.SetX(10);
test.Point.Set(20, 30);
Console.WriteLine(test.X);
Console.WriteLine($"{test.Point.X} {test.Point.Y}");
}
Point is not modified, since it is a value type, and getter gives us a copy, which makes sense. The thing I don't understand - why in this case X is modified? It is a value type also. This looks like a contradiction to me. Please help me to understand what I am missing