Re: Help constructing a class !

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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 !



.



Relevant Pages

  • Re: Getting attributs for membership provider from web.config
    ... When rewritting Initialze you stil need to get that namevaluecollection. ... I tried to us the ConfigurationManager but that didn't work. ... > You have to implement the Initialize method in your MembershipProvider ... > there you will also find the source code of the depracated Access provider ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Getting attributs for membership provider from web.config
    ... > When rewritting Initialze you stil need to get that namevaluecollection. ... >> the Initialize method is private in the Membership class ... >> You have to implement the Initialize method in your MembershipProvider ... >> much fun with your provider. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Strange Exception in NameValueCollection Class.
    ... > System.Collections.Specialized Namespace. ... I dont understand how ... > show NameValueCollection as a derived class of Hashtable. ... will ignore duplicates: ...
    (microsoft.public.dotnet.csharp.general)
  • re:Arraylist
    ... Try the "NameValueCollection" in the System.Collections.Specialized ... namespace. ... Posted Via Usenet.com Premium Usenet Newsgroup Services ...
    (microsoft.public.dotnet.languages.csharp)