网络学院 > 开发教室 > 工具平台 > VC/C#
   初探c#(十三)属性(Properties)

出处:PConline
责任编辑:pjl

[01-11-23 14:38] 作者:依栏望海


1.14 属性(Properties)

  关于属性就不用多说了。可能有点特别的是如何得到一个属性和设置一个属性。请诸位看下例:*/

public class Button: Control
{
private string caption;
public string Caption {
get {
return caption;
}
set {
caption = value;
Repaint();
}
}
}

/*
有了上面的定义,我们就可以对Button进行读取和设置它的Caption属性:*/

Button b = new Button();
b.Caption = "ABC"; // 设置
string s = b.Caption; // 读取
b.Caption += "DEF”; // 读取 & 设置


点击这里发表意见

相关文章:

 

 

 

内容搜索 
  高级搜索

本栏今日焦点