Private 'set' in C# - having trouble wrapping my brain around it

前端 未结 9 2418
傲寒
傲寒 2021-02-12 10:34

I\'ve seen a lot of example code written using something like (please forgive how horribly canned this is):

public class Test
{
   public object Thingy { get; pr         


        
9条回答
  •  无人及你
    2021-02-12 11:05

    private set is very handy for simple immutable value types.

    struct Point
    {
        public int X { get; private set; }
        public int Y { get; private set; }
        public Point(int x, int y)
        {
            this = default(Point);
            X = x;
            Y = y;
        }
    }
    

提交回复
热议问题