What is the purpose of the “get” and “set” properties in C#

前端 未结 7 1577
鱼传尺愫
鱼传尺愫 2020-12-30 12:35

I saw some get set method to set values. Can anyone tell me the purpose of this?

public string HTTP_USER_NAME
{
      get 
      {
            return UserNam         


        
7条回答
  •  温柔的废话
    2020-12-30 12:50

    Properties are just accessors over fields. They allow to do certain operations (if needed), and provide controlled access to fields.

    If you want to know when to use Properties, and when to use Only fields, Check the link Properties vs Fields – Why Does it Matter? (Jonathan Aneja)

提交回复
热议问题