我目前正在做一些课程编码,并想知道我的项目出了什么问题?不包含带2个参数的构造函数吗?
class ContactPerson
{
string name;
ContactNo telNo;
public ContactPerson(string in_Name, ContactNo in_No)
{
name = in_Name;
telNo = new ContactNo();
}
public string getName()
{
return name;
}
public ContactNo getContactInfo()
{
return telNo;
}
public void setName(string in_Name)
{
name = in_Name;
}
public void setContactInfo (ContactNo in_No)
{
telNo = in_No;
}
}
}
class ContactNo
{
string contactType;
string contactNo;
public void setContactType(string in_Type)
{
contactType = in_Type;
}
public string getContactType()
{
return contactType;
}
public void setContactNo(string in_No)
{
contactNo = in_No;
}
public string getContactNo()
{
return contactNo;
}
}
}
class Program
{
static void Main(string[] args)
{
ContactNo telNo;
telNo = new ContactNo("Mobile No: ", 95656565);
ContactPerson myFriend;
myFriend = new ContactPerson("Fred Smith", telNo);
string strName;
strName = myFriend.getName();
Console.WriteLine(" " + strName);
ContactNo outContact;
outContact = myFriend.getContactInfo();
outContact.getContactType();
Console.WriteLine(outContact);
outContact.getContactNo();
Console.WriteLine(outContact);
Console.ReadLine();
}
}
}
在节目类 “telNo =新ContactNo(” 移动否: “95656565);” theres error says不包含带有2个参数的构造函数我可以知道为什么吗?
从Java来了,对不对?请使用[real Properties](http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx)而不是'getABC()'和'setABC()'方法。 –
要详细说明@HighCore所说的,而不是getABC()和setABC,请使用公共字符串YourString {get {return _yourString} set {_yourString = value}}; –
然后你可以使用属性初始值设定项:'telNo = new ContactNo(){ContactType =“Mobile No:”,Number = 95656565};' –