Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. need help with generics - multi key lookup

need help with generics - multi key lookup

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kalyan_A
    wrote on last edited by
    #1

    Hi All, This is my first post and hope i am placing it in the right forums - I have the following class Class User Dim UserID as integer Dim IsActive as boolean Dim Username as string End Class i need to perform lookups on UserID or IsActive Get user with ID = X (returns one object) Get all active Users (returns multiple objects - possibly a list) Get all inactive users (returns multiple objcets - possibly a list) for quicker retrieval using userid, i intend to use the generics dictionary dim Users as Dictionary (Of integer, User) are there any generics implementations which allow me to use quickly retrieve all active users or inactive users as well? Just wanted to check with you experts before embarking on my own. :) Thanks in advance Kalyan

    L 1 Reply Last reply
    0
    • K Kalyan_A

      Hi All, This is my first post and hope i am placing it in the right forums - I have the following class Class User Dim UserID as integer Dim IsActive as boolean Dim Username as string End Class i need to perform lookups on UserID or IsActive Get user with ID = X (returns one object) Get all active Users (returns multiple objects - possibly a list) Get all inactive users (returns multiple objcets - possibly a list) for quicker retrieval using userid, i intend to use the generics dictionary dim Users as Dictionary (Of integer, User) are there any generics implementations which allow me to use quickly retrieve all active users or inactive users as well? Just wanted to check with you experts before embarking on my own. :) Thanks in advance Kalyan

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      you could: - just use a dictionary (key=UserId) and test IsActive as appropriate; - keep one dictionary (key=UserId), and two lists (one with active, one with inactive users); - keep two dictionaries, one with active and one with inactive users; - use a DataTable; - use lambda expressions. IMO the best choice depends a bit on the circumstances where you need it. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
      All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.


      K 1 Reply Last reply
      0
      • L Luc Pattyn

        you could: - just use a dictionary (key=UserId) and test IsActive as appropriate; - keep one dictionary (key=UserId), and two lists (one with active, one with inactive users); - keep two dictionaries, one with active and one with inactive users; - use a DataTable; - use lambda expressions. IMO the best choice depends a bit on the circumstances where you need it. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
        All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.


        K Offline
        K Offline
        Kalyan_A
        wrote on last edited by
        #3

        Hi Luc, Thanks for a quick reply. I looked at generics and was hoping there may be a complex alternative which i might find interesting :omg: i have opted for the following to keep it simple 1 dictionary for quick retrieval by userid 2 lists for containing active and inactive users. i wonder how this will scale for larger number of users! Thanks to you i learnt about lambda expressions today. :thumbsup: Go you still prefer datatables for these kind of operations when dealing with disconnected data? Cheers Kalyan

        L 1 Reply Last reply
        0
        • K Kalyan_A

          Hi Luc, Thanks for a quick reply. I looked at generics and was hoping there may be a complex alternative which i might find interesting :omg: i have opted for the following to keep it simple 1 dictionary for quick retrieval by userid 2 lists for containing active and inactive users. i wonder how this will scale for larger number of users! Thanks to you i learnt about lambda expressions today. :thumbsup: Go you still prefer datatables for these kind of operations when dealing with disconnected data? Cheers Kalyan

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          you're welcome. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
          All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups