What is internal set property in c#?

前端 未结 8 574
悲&欢浪女
悲&欢浪女 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

    Suppose you're designing an API for use by other programmers. Within this API, you have an object Foo which has a property Bar. You don't want the other programmers setting the value of Bar when they reference your assembly, but you have a need to set the value yourself from within your API. Simply declare the property as such:

    public class Foo
    {
       public string Bar { get; internal set; }
    }
    

提交回复
热议问题