using
System;
class User
... {
private string m_Name;//私有字段
private string m_Sex;//私有字段
public string Name//定义属性名称
...{
get ...{ return m_Name; }
set ...{ m_Name = value; }
}
public string Sex
...{
get ...{ return m_Sex; }
set
...{
if (value == "男" || value == "女")
...{ m_Sex = value;}
else
...{ Console.WriteLine("性别只能为男或女");}
}
}
}
class property
... {
static void Main()
...{
User zs = new User();
zs.Name = "张三";
zs.Sex = "男";
Console.WriteLine(zs.Name+" "+zs.Sex);
}
}
class User
... {
private string m_Name;//私有字段
private string m_Sex;//私有字段
public string Name//定义属性名称
...{
get ...{ return m_Name; }
set ...{ m_Name = value; }
}
public string Sex
...{
get ...{ return m_Sex; }
set
...{
if (value == "男" || value == "女")
...{ m_Sex = value;}
else
...{ Console.WriteLine("性别只能为男或女");}
}
}
}
class property
... {
static void Main()
...{
User zs = new User();
zs.Name = "张三";
zs.Sex = "男";
Console.WriteLine(zs.Name+" "+zs.Sex);
}
}