在 C# 中,我有一个 AddressBook 类,在该类中我有一个联系人列表。我有一个继承自我的抽象 Person 类的 Contact 类(它有 Name、Sex、DOB)。但是我希望每个联系人都能够拥有联系信息,所以我创建了另一个名为 ContactInfo 的类(电话号码、地址、城市)。我在弄清楚如何将 ContactInfo 属性(号码、地址等)附加到用户决定输入地址簿的每个联系人时遇到问题。下面是我的 Contact 类和我的 ContactInfo 类:
public class Contact : Person
{
public ContactInfo info, newInfo;
public Contact()
{ }
public ContactInfo GetContactInfo()
{
var info = new ContactInfo();
return info.GatherContactInfo();
}
//public ContactInfo Info { get; set; }
}
public class ContactInfo
{
public string PhoneNumber { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set;}
public Contact contact;
public ContactInfo()
{ }
public ContactInfo GatherContactInfo()
{
var newInfo = new ContactInfo();
Console.WriteLine("Enter their phone number:");
string phoneNumber = Console.ReadLine();
newInfo.PhoneNumber = StorePhoneNumber(phoneNumber);
Console.WriteLine("Enter their address: ");
string address = Console.ReadLine();
newInfo.Address = StoreAddress(address);
Console.WriteLine("Enter city: ");
string city = Console.ReadLine();
newInfo.City = StoreCity(city);
Console.WriteLine("Enter State: ");
string _state = Console.ReadLine();
newInfo.State = StoreState(_state);
return newInfo;
}