Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

choice for collections of objects in a Windows Application development project

I am a college student trying to build a small windows application using Visual Studio 2005.

Business Context:

Simulation of a computer science department that contains faculty, students, courses, advisors etc.

My question:

1) Some of the entities will obviously be the ones mentioned above. When I built the class diagram, I felt a good design choice would be that a department class would contain collections of faculty, courses advisors, degree programs etc.

What do you think will be the best collection type to capture these objects or collections of objects such as ArrayList or List ? Can you capture them as Faculty[], advisor[] etc.? If yes, how?

Thanks.
0
scarface7
Asked:
scarface7
1 Solution
 
PoeticAudioCommented:
An ArrayList is good because it's easy to use, plus it can hold any object, as long as you cast it back.

ArrayList al = new ArrayList();

//it's easy to add objects to an ArrayList!
MyObject myObject = new MyObject();
al.Add(myObject);


//it's also easy to cast back to MyObject.
foreach(MyObject myObj in al)
{
   myObj.MyMethod();
}

//or if you want to use an index, say you added 3 of MyObjects to the ArrayList and
//you wanted to call the 2nd one in the list

MyObject myObject = (MyObject)al[1];  //ArrayList is 0 based
myObject.MyMethod();

or

//here we use as to cast the 2nd entry in the ArrayList to a MyObject type and then call MyMethod
(al[1] as MyObject).MyMethod();
0
 
balajikumar75Commented:
A hastable is faster in access and in addition it gives you a key value pair where value could be a object. So retrival is based onn they key name and not list of no's as in arraylist.

I would recommend you to use a hashtable.
0
 
GENTPCommented:
use the CollectionBase

ie:

using System.Collection;


public class Faculty
{

}

public class Deptment : CollectionBase
{
 void AddFaculty(Faculty newFaculty)
{
List.Insert(newFaculty);
}

This will give you stronged typed collection. Here's a link that will provide you with more details

http://www.codeproject.com/csharp/collection1.asp

}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now