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

前端 未结 9 2412
傲寒
傲寒 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 10:59

    To answer the question of a common scenario where this might be used... In an MVP pattern, if your Model exposes some properties for your Presenter I would write

    public string Bazinga { get; private set; }
    

    Now, the Model can change this value but other classes that use it cannot.

提交回复
热议问题