Class Field in list.

  • Thread starter Thread starter jack
  • Start date Start date
J

jack

Hi,
I am creating an address book example. For the purpose i have created
2 classes
one is
ContactInfo
name
department

PhoneInfo
OfficePhone
Mobile

Now I want to design the class in such a way that when I type
ContactInfo.PhoneInfo.mobile
it should take the list of mobile numbers

im using dotnet 2.0 and know little about generics.
can we implement generics for the same.
 
I am creating an address book example. For the purpose i have created
2 classes
one is
ContactInfo
name
department

PhoneInfo
OfficePhone
Mobile

Now I want to design the class in such a way that when I type
ContactInfo.PhoneInfo.mobile
it should take the list of mobile numbers

im using dotnet 2.0 and know little about generics.
can we implement generics for the same.

I don't see where generics would come into it at all.

A few things aren't clear:
1) Is there any inheritance here?
2) Is PhoneInfo a nested class?
3) When you talk about typing ContactInfo.PhoneInfo.mobile, do you
mean in Visual Studio?

It sounds to me like your ContactInfo ought to have a reference to an
instance of PhoneInfo...

Jon
 
You should add the a PhoneInfo object to the ContactInfo class and make a
property for it that can be called by other objects. You should also make a
property in the PhoneInfo class that returns the mobile phone number.
Similary you can addd more properties as you see fit, but the code below
allows you to get the mobile phone number of a contact like this:

ContactInfo myContactInfo = new ContactInfo(...); //depending on how you set
up your constructor
string mobileNum = myContactInfo.PhoneData.Mobile;

-------------------------------------------------------------------------

class ContactInfo
{
string m_name;
string m_department;
PhoneInfo m_phoneData;

public PhoneInfo PhoneData
{
get { return m_phoneData; }
}
....
}

class PhoneInfo
{
string m_officeNum;
string m_mobileNum;

public string Mobile
{
get { return m_mobileNum; }
}
....
}


Adrian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top