public class RegistrationInformation
{
public RegistrationInformation()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public struct RegistrationInformation
{
private string firstname;
public string Firstname
{
get { return firstname; }
set { firstname = value; }
}
private string lastname;
public string Lastname
{
get { return lastname; }
set { lastname = value; }
}
private string email;
public string Email
{
get { return email; }
set { email = value; }
}
private string selectedevent;
public string SelectedEvent
{
get { return selectedevent; }
set { selectedevent = value; }
}
}
}
以上是创建的类,
以下我在default_aspx类添加公共属性RegistrationInformation
public RegistrationInformation RegistrationInformation
{
get
{
RegistrationInformation ri = new RegistrationInformation();
ri.-----
}
}
我发现照书上说ri应该有firstname和lastname等属性,但实际上没有,不知道我的代码错在那里
这一节是在入门经典3的500页,高人们帮忙看一下吧
------解决方案--------------------------------------------------------
把结构struct放到类外面,而取消你创建的类。
------解决方案--------------------------------------------------------
首先,这段代码就编译不过
类里面的一个struct 不能和类同名~
------解决方案--------------------------------------------------------
为什么要 class RegistrationInformation 内定义一个 struct RegistrationInformation ?
这个定义式没有问题的,叫 “内嵌类型”
RegistrationInformation.RegistrationInformation regInfo = RegistrationInformation.RegistrationInformation();
regInfo.Firstname = "Jing";