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. Other Discussions
  3. The Weird and The Wonderful
  4. ArrayList.Contains() isn't bool?

ArrayList.Contains() isn't bool?

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharprubyquestion
6 Posts 4 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.
  • A Offline
    A Offline
    Ankush Bansal
    wrote on last edited by
    #1

    Just saw this legacy gem

    if(myArrayList.Contains(something)==true || myArrayList.Count>0)
    {
    if(myArrayList.Contains(something)==false)
    {
    default=something;
    }
    else
    {
    default=myArrayList[0];
    }
    }

    this is for C#.net.

    OriginalGriffO M 2 Replies Last reply
    0
    • A Ankush Bansal

      Just saw this legacy gem

      if(myArrayList.Contains(something)==true || myArrayList.Count>0)
      {
      if(myArrayList.Contains(something)==false)
      {
      default=something;
      }
      else
      {
      default=myArrayList[0];
      }
      }

      this is for C#.net.

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

      If you look at MSDN[^] you will see it returns a virtual bool, so obviously you can't trust it! :laugh:

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      "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

      A 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        If you look at MSDN[^] you will see it returns a virtual bool, so obviously you can't trust it! :laugh:

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        A Offline
        A Offline
        Ankush Bansal
        wrote on last edited by
        #3

        "virtual bool" so anyone can override to make it float. :-D :thumbsup:

        OriginalGriffO 1 Reply Last reply
        0
        • A Ankush Bansal

          "virtual bool" so anyone can override to make it float. :-D :thumbsup:

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

          Well, you wouldn't want it to sink, would you? :laugh:

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          "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
          • A Ankush Bansal

            Just saw this legacy gem

            if(myArrayList.Contains(something)==true || myArrayList.Count>0)
            {
            if(myArrayList.Contains(something)==false)
            {
            default=something;
            }
            else
            {
            default=myArrayList[0];
            }
            }

            this is for C#.net.

            M Offline
            M Offline
            Member 2053006
            wrote on last edited by
            #5

            I love how the first Contains is redundant and the default does not get set if myArrayList is empty.

            B 1 Reply Last reply
            0
            • M Member 2053006

              I love how the first Contains is redundant and the default does not get set if myArrayList is empty.

              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #6

              Still worse: when the array list does not contain "something", the default is set to something. When the array list contains something, the default is set to the first element of the array list, which may or may not be "something"...

              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