我已经上课了,这是我正在制作的地址簿。 我在制作公共地址类级别对象变量时遇到问题。我不知道如何编码。
namespace Add_New_Name
{
class Address
{
public string strName;
public string strEmailAddress;
public string strComment;
public string strPhoneNumber;
public string strAddress;
//property Name
#region Property Name
public string Name
{
get
{
return strName;
}
set
{
strName = value;
}
} //end property Address
#endregion
//property Email Address
#region Email Address
public string EmailAddress
{
get
{
return strEmailAddress;
}
set
{
strEmailAddress = value;
}
} //end property Email Address
#endregion
//property Comment
#region Comment
public string Comment
{
get
{
return strComment;
}
set
{
strComment = value;
}
}//end property Comment
#endregion
//property Phone Number
#region Phone Number
public string PhoneNumber
{
get
{
return strPhoneNumber;
}
set
{
strPhoneNumber = value;
}
}
#endregion
//property Address
#region Address
public string address
{
get
{
return strAddress;
}
set
{
strAddress = value;
}
}
#endregion
//constructor
#region Constructor
public Address (string sName, string sEmailAddress, string sComment, string sPhoneNumber, string sAddress)
{
Name = sName; //property name
EmailAddress = sEmailAddress; //property address
Comment = sComment; // property comment
PhoneNumber = sPhoneNumber; // property phone number
address = sAddress; // property address
}
#endregion
}
}
答案 0 :(得分:1)
尝试更改
class Address
到
public class Address
然后您可以像这样创建对象(编辑以显示带参数的构造函数):
var myAddress = new Address("me", "email", "code is cool", "a number", "an address");