What is internal set property in c#?

前端 未结 8 669
悲&欢浪女
悲&欢浪女 2021-02-01 01:01

I just came across an unknown concept of c# for me. Can anyone tell me what the purpose of an internal set property is? What is its use? I know internal keyword is used for work

8条回答
  •  不要未来只要你来
    2021-02-01 01:38

    Properties in C# 2.0

    In C# 2.0 you can set the accessibility of get and set.

    The code below shows how to create a private variable with an internal set and public get. The Hour property can now only be set from code in the same module (dll), but can be accessed by all code that uses the module (dll) that contains the class.

    // private member variables
    private int hour;
    
    // create a property
    public int Hour
    {
      get { return hour; }
      internal set { hour = value; }
    }
    

提交回复
热议问题