doubt in csharp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Baskar RajaSekharan

    doubt in csharp

    Hi,

    I have one doubt in c_sharp. Please let me know is there any
    Collection or Dictonery having the Sort facility. I want to sort a list of
    Numbers. how to do that? For Example i am going to store some value in
    either Hash dictonery or ArrayList... With out writing code is there any
    way to Sort?

    Note: Array List is not working fine.

    Regards,
    R.Baskar


  • Jon Skeet [C# MVP]

    #2
    Re: doubt in csharp

    Baskar RajaSekharan <rbk@srasys.co. in> wrote:[color=blue]
    > I have one doubt in c_sharp. Please let me know is there any
    > Collection or Dictonery having the Sort facility. I want to sort a list of
    > Numbers. how to do that? For Example i am going to store some value in
    > either Hash dictonery or ArrayList... With out writing code is there any
    > way to Sort?[/color]

    Yes: ArrayList.Sort.
    [color=blue]
    > Note: Array List is not working fine.[/color]

    That suggests you're misusing it. Could you give an example?

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Bogdan Lachendro

      #3
      Re: doubt in csharp

      On 11/6/2003 2:30 PM, Baskar RajaSekharan wrote:
      [color=blue]
      > I have one doubt in c_sharp. Please let me know is there any
      > Collection or Dictonery having the Sort facility. I want to sort a list of
      > Numbers. how to do that? For Example i am going to store some value in
      > either Hash dictonery or ArrayList... With out writing code is there any
      > way to Sort?
      >
      > Note: Array List is not working fine.[/color]

      What do you mean it doesn't work fine? What Sort(..) method do you use?
      Are you using right IComparer? Are the objects you want to sort IComparable?

      regards,
      Bogdan

      Comment

      • Ignacio Machin \( .NET/ C#  MVP \)

        #4
        Re: doubt in csharp

        Hi,

        ArrayList.Sort( ) should do the trick, now remember that the elements of the
        arraylist MUST implement IComparable.

        These are the things I would check:
        1- that all elements of the list are of the same type.
        2- that this type implement IComparable ( you say that they are numbers, if
        you mean with this that they are "int" you are ok with this).

        if the above is true then it should work fine, otherwise post the code
        and/or the error you are getting


        Cheers,

        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation

        "Baskar RajaSekharan" <rbk@srasys.co. in> wrote in message
        news:%23dWlYnGp DHA.2488@TK2MSF TNGP12.phx.gbl. ..[color=blue]
        > Hi,
        >
        > I have one doubt in c_sharp. Please let me know is there any
        > Collection or Dictonery having the Sort facility. I want to sort a list[/color]
        of[color=blue]
        > Numbers. how to do that? For Example i am going to store some value in
        > either Hash dictonery or ArrayList... With out writing code is there any
        > way to Sort?
        >
        > Note: Array List is not working fine.
        >
        > Regards,
        > R.Baskar
        >
        >[/color]


        Comment

        • 100

          #5
          Re: doubt in csharp

          Sorted collections are: ArrayList (I don't know what you mean by *it is not
          working fine* and SortedList if you need dictionary like collection.

          HTH
          B\rgds
          100

          "Baskar RajaSekharan" <rbk@srasys.co. in> wrote in message
          news:%23dWlYnGp DHA.2488@TK2MSF TNGP12.phx.gbl. ..[color=blue]
          > Hi,
          >
          > I have one doubt in c_sharp. Please let me know is there any
          > Collection or Dictonery having the Sort facility. I want to sort a list[/color]
          of[color=blue]
          > Numbers. how to do that? For Example i am going to store some value in
          > either Hash dictonery or ArrayList... With out writing code is there any
          > way to Sort?
          >
          > Note: Array List is not working fine.
          >
          > Regards,
          > R.Baskar
          >
          >[/color]


          Comment

          • Alvin Bruney

            #6
            Re: doubt in csharp

            OR,

            in addition to all these other good suggestions, you could use this gem:
            SortedList.

            It's a hybrid between an arraylist and dictionary object which keeps its
            contents ordered so you don't have to explicitly call a sort method.

            When items indexing is used, it behaves like an array, otherwise it behaves
            like a hash.
            regards

            --


            -----------
            Got TidBits?
            Get it here: www.networkip.net/tidbits
            "Baskar RajaSekharan" <rbk@srasys.co. in> wrote in message
            news:#dWlYnGpDH A.2488@TK2MSFTN GP12.phx.gbl...[color=blue]
            > Hi,
            >
            > I have one doubt in c_sharp. Please let me know is there any
            > Collection or Dictonery having the Sort facility. I want to sort a list[/color]
            of[color=blue]
            > Numbers. how to do that? For Example i am going to store some value in
            > either Hash dictonery or ArrayList... With out writing code is there any
            > way to Sort?
            >
            > Note: Array List is not working fine.
            >
            > Regards,
            > R.Baskar
            >
            >[/color]


            Comment

            Working...