我似乎无法通过其他类的公共属性访问我的私有成员变量。我试图通过学生类在StudentList
中实例化一些Student
对象。我已经做过,但不能为我的生活记住或找到任何有用的东西。我对编程比较陌生,所以对我来说很简单。通过公共属性访问私有变量
学生类代码
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类代码,现在基本上是空白。我一直在试图让intellisense访问我的其他课程,但没有运气到目前为止。我必须错过简单的东西。
public partial class StudentList : Page
{
}
你有你的班级的实例访问? – 2013-02-28 04:04:09
你想从StudentList访问学生? – 2013-02-28 04:04:46
@ cuong le,是 – Milne 2013-02-28 04:05:39