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. Problem With sorting of array [modified]

Problem With sorting of array [modified]

Scheduled Pinned Locked Moved C#
helpalgorithmsdata-structurestutorial
8 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.
  • S Offline
    S Offline
    sindhutiwari
    wrote on last edited by
    #1

    hi, i m having a integer array which i need to sort frequently example code: int[] intarray = new intarray[5]; in between the code array.sort(intarray); now this code runs fine sometime and sometime it fails error is Failed to compare two elements in the array. pla if anyone is having any idea abt this then plz do let me know regards sindhu tiwari

    its me sid

    modified on Friday, January 04, 2008 3:26:44 AM

    V 1 Reply Last reply
    0
    • S sindhutiwari

      hi, i m having a integer array which i need to sort frequently example code: int[] intarray = new intarray[5]; in between the code array.sort(intarray); now this code runs fine sometime and sometime it fails error is Failed to compare two elements in the array. pla if anyone is having any idea abt this then plz do let me know regards sindhu tiwari

      its me sid

      modified on Friday, January 04, 2008 3:26:44 AM

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      Array.Sort() fails for vanilla integer arrays? :wtf: While it's possible, I think it's highly unlikely. Have you googled for the exact exception message? I doubt if you've given the exact message, and Google returns no results.

      Cheers, Vikram.


      "If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy

      S 1 Reply Last reply
      0
      • V Vikram A Punathambekar

        Array.Sort() fails for vanilla integer arrays? :wtf: While it's possible, I think it's highly unlikely. Have you googled for the exact exception message? I doubt if you've given the exact message, and Google returns no results.

        Cheers, Vikram.


        "If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy

        S Offline
        S Offline
        sindhutiwari
        wrote on last edited by
        #3

        this is the error which i got "Failed to compare two elements in the array." and searched on google too but unfortunately dint got proper result if u any way to sort or any idea then plz do let me now sindhu tiwari

        its me sid

        P 1 Reply Last reply
        0
        • S sindhutiwari

          this is the error which i got "Failed to compare two elements in the array." and searched on google too but unfortunately dint got proper result if u any way to sort or any idea then plz do let me now sindhu tiwari

          its me sid

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Well, could you show us what values you've put in the array then?

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          S 1 Reply Last reply
          0
          • P Pete OHanlon

            Well, could you show us what values you've put in the array then?

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            S Offline
            S Offline
            sindhutiwari
            wrote on last edited by
            #5

            ya sure intarray[0]=1; intarray[1]=2; intarray[2]=null; intarray[3]=3; intarray[4]=null; i hope this will help you ..thanks for response regards sindhu tiwari

            its me sid

            P 1 Reply Last reply
            0
            • S sindhutiwari

              ya sure intarray[0]=1; intarray[1]=2; intarray[2]=null; intarray[3]=3; intarray[4]=null; i hope this will help you ..thanks for response regards sindhu tiwari

              its me sid

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              It certainly does. You can't sort an array of ints if they have nulls in them. Convert intarray into a nullable int instead, i.e. make it int?. Mind you, I don't see how you could have got this code past the compiler because an ordinary int can't contain a null value so the system should have choked on it.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              S 1 Reply Last reply
              0
              • P Pete OHanlon

                It certainly does. You can't sort an array of ints if they have nulls in them. Convert intarray into a nullable int instead, i.e. make it int?. Mind you, I don't see how you could have got this code past the compiler because an ordinary int can't contain a null value so the system should have choked on it.

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                S Offline
                S Offline
                sindhutiwari
                wrote on last edited by
                #7

                would u plz tell me how to make it a nullable int array......... regards sindhu tiwari

                its me sid

                P 1 Reply Last reply
                0
                • S sindhutiwari

                  would u plz tell me how to make it a nullable int array......... regards sindhu tiwari

                  its me sid

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  I already did. Add the question mark (?) after the int. So you would have

                  int?[] intarray = new int?[5];
                  

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles

                  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