C#编写类

来源:百度知道 编辑:UC知道 时间:2024/06/27 03:26:40
编写MySchool中的Student类
包含的属性有
年龄(0-100)不符合的设为18
姓名(只读属性)
爱好(读写)
给属性赋值并打印出来
用 Visual Studio 2005输出 Console.WrtieLine

public class Student
{
private string m_Name = "";
private int m_Age = 18;
private string m_Hobby = "";

[ReadOnly(true)]
public string Name
{
get { return m_Name; }
}
public int Age
{
get { return m_Age; }
set
{
if (value > 0 && value <= 100)
{
m_Age = value;
}
else
{
m_Age = 18;
}
}
}
public string Hobby
{
get { return m_Hobby; }
set { m_Hobby = value; }
}
public override string ToString()
{
string strValue = "";
strV