Re: Help constructing a class !
- From: "Mark Fitzpatrick" <markfitz@xxxxxxxxxx>
- Date: Thu, 12 Oct 2006 17:49:55 -0500
You use a collection instead. You could actually do this in several ways.
You could create a NameValueCollection (located in the
System.Collections.Specialized namespace). This way you could put an id and
name into the collection. In this case, most people would probably put the
ID number as the name, and the name of the project as the value. You create
the namevaluecollection just as you would any other field. Then, you can add
projects to it as needed.
for example:
// initialize the collection
private NameValueCollection col = new NameValueCollection
then you can add to it such as:
col.Add(Id1.ToString(),"ProjectName1");
That's assuming that Id1 is a number.
Now, what if you wanted to make that a property. You woud do it like so
public NameValueCollection Projects
{
get
{
return col;
}
set
{
col = value;
}
}
You cuold then access it like so:
Worker.Projects.Add("1","Project1");
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Big George" <jbeteta@xxxxxxxxx> wrote in message
news:1160692408.669201.243120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,
I develop in ASP.NET with VB.NET code.
I need some help constructing a class: Worker. I'm designing the
properties of this class.
The class is filled reading tables in database.
Properties of Class Worker:
- ID_Card
- Names of Person
- ID_Current_Company
- Name of Current Company
- Is Worker working at the company? (Yes, No)
- Projects that worker worked in
- Project 1 (ID and name)
- Project 2 (ID and name)
- Project 3 (ID and name)
- ...
My problem is with property Projects_Worked_In. A worker could have
been in many projects. I don't know how many projects a worker has
worked at. It could be only 1 project or 5 projects.
How would you desing this property Projects_Worked_In of class Worker?
I was thinking to:
- Define 50 properties like Project1, Project2, Project3,... Project50,
all of them initialized in NULL
- Define a property Number_Of_Projects and according to that I will
know if I have to display Project1, Project2, Project3, etc.
Problem is what happen if Number_Of_Projects > 50
Thank you for your help !
.
- References:
- Help constructing a class !
- From: Big George
- Help constructing a class !
- Prev by Date: Re: Cryptography in ASP.NET stopped working
- Next by Date: Why do I keep getting a null (or other) error with gridview and DataRowView?
- Previous by thread: Help constructing a class !
- Next by thread: Re: Help constructing a class !
- Index(es):
Relevant Pages
|