主题:帮我看一个简单的代码
using System;
public class Student
{
public int StudID;
private string StudName;
public string StudSex;
public int StudAge;
public double StudMath;
public double StudEnglish;
public double Totle;
public double studmath
{
get { return StudMath; }
set { StudMath = value; }
}
public string studname
{
get { return StudName; }
set { StudName = value; }
}
public double totle
{
get { return Totle; }
set { Totle = (StudEnglish + StudMath); }
}
public Student()
{ }
public Student(int id, string name, string sex, int age, double math, double english)
{
StudID = id;
StudName = name;
StudSex = sex;
StudAge = age;
StudMath = math;
StudEnglish = english;
}
}
public class Test
{
public static void Main(string[] args)
{
Student astudent = new Student(05094049, "caogongpu", "男", 22, 80.0, 80.0);
Console.WriteLine(astudent.StudID);
Console.WriteLine(astudent.studname);
Console.WriteLine(astudent.StudMath);
Console.WriteLine(astudent.StudEnglish);
Console.WriteLine(astudent.totle);
astudent.studname="liuwei";
astudent.studmath=90;
Console.WriteLine(astudent.studname+""+astudent.studmath);
Console.WriteLine(astudent.totle);
Console.Read();
}
}
调用astudent的totle属性,执行结构总是0,应该是StudMath+StudEnglish的和呀
public class Student
{
public int StudID;
private string StudName;
public string StudSex;
public int StudAge;
public double StudMath;
public double StudEnglish;
public double Totle;
public double studmath
{
get { return StudMath; }
set { StudMath = value; }
}
public string studname
{
get { return StudName; }
set { StudName = value; }
}
public double totle
{
get { return Totle; }
set { Totle = (StudEnglish + StudMath); }
}
public Student()
{ }
public Student(int id, string name, string sex, int age, double math, double english)
{
StudID = id;
StudName = name;
StudSex = sex;
StudAge = age;
StudMath = math;
StudEnglish = english;
}
}
public class Test
{
public static void Main(string[] args)
{
Student astudent = new Student(05094049, "caogongpu", "男", 22, 80.0, 80.0);
Console.WriteLine(astudent.StudID);
Console.WriteLine(astudent.studname);
Console.WriteLine(astudent.StudMath);
Console.WriteLine(astudent.StudEnglish);
Console.WriteLine(astudent.totle);
astudent.studname="liuwei";
astudent.studmath=90;
Console.WriteLine(astudent.studname+""+astudent.studmath);
Console.WriteLine(astudent.totle);
Console.Read();
}
}
调用astudent的totle属性,执行结构总是0,应该是StudMath+StudEnglish的和呀