Results 1 to 4 of 4

Thread: [2.0] Having problems building a procedure... please help!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question [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!!

    Dekel C.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2.0] Having problems building a procedure... please help!

    Post the code you are using along with the errors that you are getting.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    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!!


    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
  •  



Click Here to Expand Forum to Full Width