//对象的关系:共享、包含、继承
public partial class lei_gongxiang: System.UI.Page
{
public class User
{
private static int count; //统计有多少个对象
private static string name; //定义每个对象的用户名
public User()
{
count ++;
}
static User() //静态构造函数,用于初始化静态变量的值,对静态变量作绑定检查和有效性检查
{
count = 0;
name = "初始值";
}
public string Name //姓名属性外露
{
get {return name; }
set {name = value; }
}
public static string OneName //只是为了显示初始值
{
get {return name; }
}
public static int Count
{
get {return count; }
}
public static string Mn(string nname )
{
return "个对象,共享方法后的结果是" + nname;
}
}
protected void Page_Load()
{
Response.Write("目前是:" + User.Count + "个对象,初始值是:" + User.OneName );
User u1 = new User();
u1.Name = "aidd2008";
Response.Write("<br/>目前是:" + User.Count + User.Mn(u1.Name ) );
}
}
{
public class User
{
private static int count; //统计有多少个对象
private static string name; //定义每个对象的用户名
public User()
{
count ++;
}
static User() //静态构造函数,用于初始化静态变量的值,对静态变量作绑定检查和有效性检查
{
count = 0;
name = "初始值";
}
public string Name //姓名属性外露
{
get {return name; }
set {name = value; }
}
public static string OneName //只是为了显示初始值
{
get {return name; }
}
public static int Count
{
get {return count; }
}
public static string Mn(string nname )
{
return "个对象,共享方法后的结果是" + nname;
}
}
protected void Page_Load()
{
Response.Write("目前是:" + User.Count + "个对象,初始值是:" + User.OneName );
User u1 = new User();
u1.Name = "aidd2008";
Response.Write("<br/>目前是:" + User.Count + User.Mn(u1.Name ) );
}
}