473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Class Field in list.

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.

Jul 20 '07 #1
2 1429
On Jul 20, 5:59 am, jack <gautams.m...@gmail.comwrote:
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

Jul 20 '07 #2

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.
--
[Please mark my answer if it was helpful to you]


"jack" wrote:
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.

Jul 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dinks | last post by:
Hi, I'm new to C++ and have been assigned a task which i dont completely understand. Any help would be greately appreciated. Here is the problem: The class "linkedListType" use the "assert"...
6
by: SearedIce | last post by:
Consider the following simplified hypothetical code: #include <iostream.h> class rabbit { public: rabbit() {x = 3; y = 3; /*code here to set field to 1*/} void runtocage(); int x;
16
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I...
0
by: Miguel Dias Moura | last post by:
Hello, I am saving a complex type in Asp.Net 2.0 profile. I am using an SQL 2005 database as a profile provider. I have been consulting MSDN as help to create my class. (Please, see my code...
4
by: tascien | last post by:
Hi guys, I have a class object I want to expose in a webservice class... How can I make sure that all objects including subclasses are exposed in WSDL. here is an example: Public Class Lists '<...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
4
by: zfareed | last post by:
#include <iostream> #include <fstream> using namespace std; template<class ItemType> class SortedList { private:
1
SamKL
by: SamKL | last post by:
Hey, I'm no expert on PHP, and I have somewhat of an understanding of object oriented code. Anyway, getting right to the problem. I'm using PHP4, so base it off of that. Basically I have 2...
22
by: phil.pellouchoud | last post by:
I did some searching online and i couldn't find anything in reference to this. I am using MinGW, gcc 4.3 and am having the following compilation issue: class CFoo { public: ...
1
by: nuffnough | last post by:
I have defined two classes with one common field (called code) and several different fields. In class A there is only one instance of any given code as all items are individual. In class B, there...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.