[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!!
:wave:
Re: [2.0] Having problems building a procedure... please help!
Post the code you are using along with the errors that you are getting.
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.
Re: [2.0] Having problems building a procedure... please help!
Quote:
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!!
:wave:
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.