c# 新手问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 13:38:37
帮我翻译一下,最好能模拟一下其运行过程
public class Photo {

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

public int PhotoID { get { return _id; } }
public int AlbumID { get { return _albumid; } }
public string Caption { get { return _caption; } }

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

}

定义了一个Photo类,此类包含:

三个私有变量( _id,_albumid,_caption);
三个只读属性(PhotoID,AlbumID,Caption);

public Photo(int id, int albumid, string caption)为构造函数,当类被实例化时通过参数给变量赋值

定义一个Photo类有三个属性而已,没有什么运行过程

三个私有变量,三个公有属性来获取已定义的三个变量,定义一个带参数的构造函数来实现给三个私有变量赋值