【发布时间】:2015-08-31 13:54:33
【问题描述】:
public class StudentNames : INotifyPropertyChanged
{
string firstname
string surname
public string FirstName
{
get
{
return firstname;
}
set
{
if (firstname != value)
{
firstname = value;
OnPropertyChanged("FirstName");
}
}
}
public string Surname
{
get
{
return surname
}
set
{
if (surname != value)
{
surname = value;
OnPropertyChanged("Surname");
}
}
}
}
public class StudentDetails : INotifyPropertyChanged
{
string address StudentNames sn
public string SN
{
get
{
return sn;
}
set
{
if (sn != value)
{
sn = value;
OnPropertyChanged("SN");
}
}
}
public string Address
{
get
{
return address;
}
set
{
if (address != value)
{
address = value;
OnPropertyChanged("Address");
}
}
}
}
在其他地方我有逻辑:
StudentDetails sd = new StudentDetails()
sd.StudentNames.FirstName = "John"//this part gives me a runtime error
它编译但我得到一个运行时错误:
“对象引用未设置为对象的实例。”
【问题讨论】:
-
sn是string还是StudentNames的实例?不清楚。请格式化并更正您的代码。
标签: c# wpf class properties