我似乎无法通过来自不同类的公共属性访问我的私有成员变量。我正在尝试通过学生类实例化一些Student
对象。StudentList
我以前做过,但在我的一生中无法记住或找到任何有效的方法。我对编程比较陌生,所以对我来说放轻松。
学生班级代码
public partial class Student : Page
{
public int StudentID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public double CurrentSemesterHours { get; set; }
public DateTime UniversityStartDate { get; set; }
public string Major { get; set; }
public string FullName
{
get { return FirstName + " " + LastName; }
}
new DateTime TwoYearsAgo = DateTime.Now.AddMonths(-24);
public Boolean InStateEligable
{
get
{
if (UniversityStartDate < TwoYearsAgo) // at first glance this looks to be wrong but when comparing DateTimes it works correctly
{
return true;
}
else { return false; }
}
}
public decimal CalculateTuition()
{
double tuitionRate;
if (InStateEligable == true)
{
tuitionRate = 2000;
}
else
{
tuitionRate = 6000;
}
decimal tuition = Convert.ToDecimal(tuitionRate * CurrentSemesterHours);
return tuition;
}
public Student(int studentID, string firstName, string lastName, double currentSemesterHours, DateTime universityStartDate, string major)
{
StudentID = studentID;
FirstName = firstName;
LastName = lastName;
CurrentSemesterHours = currentSemesterHours;
UniversityStartDate = universityStartDate;
Major = major;
}
}
StudentList 类代码现在基本上是空白的。我一直在搞乱它,试图让智能感知访问我的其他课程,但到目前为止还没有运气。我一定错过了一些简单的东西。
public partial class StudentList : Page
{
}