What is internal set property in c#?

2020-05-20 05:53发布

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 working within an assembly.

标签: c#
7条回答
一夜七次
2楼-- · 2020-05-20 06:40

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; }
}
查看更多
登录 后发表回答