C#刚开始学 问问大神们在score属性封装中的if语句为什么没有执行?
public class student{
private int Id;
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private DateTime brithday;
public DateTime Brithday
{
get { return brithday; }
set { brithday = value; }
}
private int score;
public int Score
{
get { return score; }
set { if (score>100) score =100;else if (score>=0) score = value;else score=0 ; }
public string dj;
public student() { }
public student(int xh, string xm)
{ Id = xh; name = xm; }
public student(int xh, string xm, DateTime bri, int cj)
{ Id = xh; name = xm; brithday = bri; cj = score; }
public void inscore()
{
Console.Write("学号:");
Id = int.Parse(Console.ReadLine());
Console.Write("姓名:");
name = Console.ReadLine();
Console.Write("生日:");
brithday = Convert.ToDateTime(Console.ReadLine());
Console.Write("总分:");
score = int.Parse(Console.ReadLine());
}
public string ScoreDj(int cj)
{
string dj;
if (cj>= 90) dj = "优秀";
else if (cj>= 80) dj = "良好";
else if (cj>= 70) dj = "中等";
else if (cj>= 60) dj = "及格";
else dj = "不及格";
return dj;
}
public void Display()
{ Console.WriteLine(" {0}, {1}, {2}, {3}, {4}", Id, name, brithday, score, ScoreDj(score)); }
}
class Program
{
const int Max = 100;
static void sort(int n, params student[] p) //采用冒泡排序法排序
{
int i, j;
student tmp;
for (i = 0; i< n - 1; i++)
{
for (j = 0; j < n - i - 1; j++)
if (p[j + 1].Score> p[j].Score)
{ tmp = p[j + 1]; //p[j+1]<->p[j]
p[j + 1] = p[j];
p[j] = tmp;
}
}
}
static void Main(string[] args)
{ int n, i;
student[] p = new student[Max]; //定义对象引用数组
Console.Write("n:");
n = int.Parse(Console.ReadLine());
for (i = 0; i< n; i++) //创建对象引用的实例
p[i] = new student();
for (i = 0; i< n; i++)
{
Console.WriteLine("输入第{0}个学生数据:", i + 1);
p[i].inscore();
}
Console.WriteLine("排序前:");
Console.WriteLine("\t学号\t姓名\t生日\t成绩\t成绩等级");
for (i = 0; i< n; i++)
{
Console.Write("序号{0}:", i + 1);
p[i].Display();
}
sort(n, p); //按总分降序排序
Console.WriteLine("排序后:");
Console.WriteLine("\t学号\t姓名\t生日\t成绩\t成绩等级");
for (i = 0; i< n; i++)
{
Console.Write("第{0}名:", i + 1);
p[i].Display();
}
Console.Read();
}
}
}