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. C#
  4. SortedList

SortedList

Scheduled Pinned Locked Moved C#
helptutorialquestion
7 Posts 6 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.
  • M Offline
    M Offline
    Morgs Morgan
    wrote on last edited by
    #1

    Hi guys does anyone know how to check if a sortedlist is empty or not? I tried using the 'capacity' and keys|values 'count' property but none work Anyone with a different approach? help Morg

    D OriginalGriffO A P H 5 Replies Last reply
    0
    • M Morgs Morgan

      Hi guys does anyone know how to check if a sortedlist is empty or not? I tried using the 'capacity' and keys|values 'count' property but none work Anyone with a different approach? help Morg

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      Capacity won't tell you if it's empty or not (if it's 0 then it's empty, but it could be empty and > 0). Count should - what doesn't work about it?

      Dave

      If this helped, please vote & accept answer!

      Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      M 1 Reply Last reply
      0
      • M Morgs Morgan

        Hi guys does anyone know how to check if a sortedlist is empty or not? I tried using the 'capacity' and keys|values 'count' property but none work Anyone with a different approach? help Morg

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Use the Count property:

                SortedList<int, string> sl = new SortedList<int, string>();
                sl.Add(4, "four");
                sl.Add(3, "three");
                MessageBox.Show(sl.Count.ToString());
        

        Gives "2".

                SortedList<int, string> sl = new SortedList<int, string>();
                //sl.Add(4, "four");
                //sl.Add(3, "three");
                MessageBox.Show(sl.Count.ToString());
        

        Gives "0".

        You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • M Morgs Morgan

          Hi guys does anyone know how to check if a sortedlist is empty or not? I tried using the 'capacity' and keys|values 'count' property but none work Anyone with a different approach? help Morg

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #4

          Why do you think that the Count property is inaccurate? Can you give an example of the exact problem you are facing. Alan.

          1 Reply Last reply
          0
          • M Morgs Morgan

            Hi guys does anyone know how to check if a sortedlist is empty or not? I tried using the 'capacity' and keys|values 'count' property but none work Anyone with a different approach? help Morg

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            return ( 42 ) ;

            1 Reply Last reply
            0
            • M Morgs Morgan

              Hi guys does anyone know how to check if a sortedlist is empty or not? I tried using the 'capacity' and keys|values 'count' property but none work Anyone with a different approach? help Morg

              H Offline
              H Offline
              hadad
              wrote on last edited by
              #6

              The count property can determine whether the list is empty or not if it is 0 so the list is empty

              Dad

              1 Reply Last reply
              0
              • D DaveyM69

                Capacity won't tell you if it's empty or not (if it's 0 then it's empty, but it could be empty and > 0). Count should - what doesn't work about it?

                Dave

                If this helped, please vote & accept answer!

                Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                M Offline
                M Offline
                Morgs Morgan
                wrote on last edited by
                #7

                Cool it works fine now...it was just logic

                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