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. Repeat Value

Repeat Value

Scheduled Pinned Locked Moved C#
question
3 Posts 3 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
    mm310
    wrote on last edited by
    #1

    How i can Remove Repeat Value in ArrayList ?

    G P 2 Replies Last reply
    0
    • M mm310

      How i can Remove Repeat Value in ArrayList ?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You can sort the ArrayList, then the duplicate values will be next to each other so that you easily can find them. Depending on what you use the list for, it might be much easier to remove the duplicate values before they even end up in the ArrayList. If you for example get the values from a database, it's much easier to just not fetch the duplicate values at all. You can use a Hashtable to make it easier to determine if a value already exists in the list.

      --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • M mm310

        How i can Remove Repeat Value in ArrayList ?

        P Offline
        P Offline
        Pradeep C
        wrote on last edited by
        #3

        You could do something like this : void Main(string[] args) { ArrayList ar = new ArrayList(); ar.Add(5); ar.Add(2); ar.Add(6); ar.Add(5); ar.Add(8); ar.Add(9); ar.Add(1); ar.Add(1); ar.Add(9); ar.Add(5); RemoveDuplicates(ar); } void RemoveDuplicates(ArrayList ar) { ar.Sort(); for (int i = ar.Count - 1; i > 0; i--) { if (ar[i].Equals(ar[i - 1])) { ar.RemoveAt(i); } } }

        --- "Drawing on my superior command of language I said nothing."

        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