zoukankan      html  css  js  c++  java
  • C#中get与set方法

    public class Photo {

     private int _id;
     private int _albumid;
     private string _caption;

     public int PhotoID { get { return _id; }
        set{this._id =value;} }

     public int AlbumID { get { return _albumid; }
            set{this._albumid =value;}}

     public string Caption { get { return _caption; }
        set{this._caption =value;}}

     public Photo(int id, int albumid, string caption) {
      _id = id;
      _albumid = albumid;
      _caption = caption;
     }

    }
    通俗来讲:get是获取值  set是设置值

    比如这句: get { return _id; }
    如果调用这个get方法 就能获得方法return的 this._id =value(返回的值)
    调用方法:Console.Write(对象 _id);(输出该属性的值)

    比如这句:set{this._id =value;} 
    如果调用这个set方法 就可以重新设置_id的值 value就是你新设置的值
    调用方法:对象._id="新值";(为该属性附新值)

  • 相关阅读:
    redis哨兵高可用
    数据库主从搭建
    docker 补充
    docker 进阶操作
    docker 简介
    数据可视化(Matplotlib)
    数据操作
    pandas练习
    Pandas简介
    python mysql utf-8 latin
  • 原文地址:https://www.cnblogs.com/strivers/p/1890106.html
Copyright © 2011-2022 走看看