Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

Class Field in list.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jack - 20 Jul 2007 05:59 GMT
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.
Jon Skeet [C# MVP] - 20 Jul 2007 08:35 GMT
> I am creating an address book example. For the purpose i have created
> 2 classes
[quoted text clipped - 13 lines]
> 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
Adrian Voicu - 20 Jul 2007 13:40 GMT
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.
Signature

[Please mark my answer if it was helpful to you]

> Hi,
> I am creating an address book example. For the purpose i have created
[quoted text clipped - 14 lines]
> im using dotnet 2.0 and know little about generics.
> can we implement generics for the same.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.