|
-
May 22nd, 2006, 12:54 PM
#1
Thread Starter
Fanatic Member
[2.0] Having problems building a procedure... please help!
Hello my friends!
I have a list of items (which I have created).
Each item has a property that can be set called year.
I want to create a new list, which will contain a number of lists of items.
Each list will contain all the items that has the same year in their property.
I've tried to do this my self but I kept getting all these errors...
can anyone help??
thanks!!
-
May 22nd, 2006, 12:57 PM
#2
Re: [2.0] Having problems building a procedure... please help!
Post the code you are using along with the errors that you are getting.
-
May 22nd, 2006, 06:13 PM
#3
Re: [2.0] Having problems building a procedure... please help!
What's a "list"? Do you mean an instance of the List class or are you speaking more generally? Terminology is important because we have no prior knowledge of what you're doing so don't assume anything.
-
May 23rd, 2006, 01:34 AM
#4
Hyperactive Member
Re: [2.0] Having problems building a procedure... please help!
 Originally Posted by dekelc
Hello my friends!
I have a list of items (which I have created).
Each item has a property that can be set called year.
I want to create a new list, which will contain a number of lists of items.
Each list will contain all the items that has the same year in their property.
I've tried to do this my self but I kept getting all these errors...
can anyone help??
thanks!!

Well if I understand you correctly, you want a dictionary of lists. Like an associative array that stores a linked list of objects.
Code:
Dictionary<string,List<CustomYearObject>> LookupObject = new Dictionary<string,List<CustomYearObject>>();
if(LookupObject.ContainsKey(myYearObject.Year))
{
LookupObject[myYearObject.Year].Add(myYearObject);
}
else
{
List<CustomYearObject> myNewList = new List<CustomYearObject>();
myNewList.Add(myYearObject);
LookupObject.Add(myYearObject.Year, MyNewList);
}
You can iterate through the dictionary and lists in foreach loops
Code:
foreach(string y in LookupObject.Keys)
{
foreach(CustomYearObject cyo in LookupObject[y])
{
Console.WriteLine(cyo.Year);
}
}
Rate my post if it helped you.
Last edited by umilmi81; May 23rd, 2006 at 01:47 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|