just array.sort desc simple one dimension with writing comparer???

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

    #1

    just array.sort desc simple one dimension with writing comparer???

    i build a string[]

    string eProduct = "#blah#ablah#bb bb";
    StringBuilder sb = new StringBuilder(e Product);
    eProduct = sb.Replace("#", "").ToStrin g();
    string[] aProducts= eProduct.Split( ';');

    then I sort asc or desc
    Array.Sort so simple, is there not some just as simple without writing
    comparer etc
    just to Array.Sort DESC?

    if( (numberDiv%2) != 0 ){

    //sort desc PLEASE

    Array.Sort(aPro ducts, DESC); ???????? does not work
    else
    //sort asc
    Array.Sort(aPro ducts);

    --
    cindy
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: just array.sort desc simple one dimension with writing comparer???

    Cindy,

    Unfortunately, no, there is not. However, writing such an
    implementation is completely trivial. You could do it in less than five
    minutes. Just negate the value returned to you by the static Compare method
    on string (when passing the two strings).

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "cindy" <cmello@nospam. nospam> wrote in message
    news:AE7F267E-E48E-47B5-A2FC-3A8CEE58AAE2@mi crosoft.com...[color=blue]
    >i build a string[]
    >
    > string eProduct = "#blah#ablah#bb bb";
    > StringBuilder sb = new StringBuilder(e Product);
    > eProduct = sb.Replace("#", "").ToStrin g();
    > string[] aProducts= eProduct.Split( ';');
    >
    > then I sort asc or desc
    > Array.Sort so simple, is there not some just as simple without writing
    > comparer etc
    > just to Array.Sort DESC?
    >
    > if( (numberDiv%2) != 0 ){
    >
    > //sort desc PLEASE
    >
    > Array.Sort(aPro ducts, DESC); ???????? does not work
    > else
    > //sort asc
    > Array.Sort(aPro ducts);
    >
    > --
    > cindy[/color]


    Comment

    • Helge Jensen

      #3
      Re: just array.sort desc simple one dimension with writing comparer???



      Nicholas Paldino [.NET/C# MVP] wrote:[color=blue]
      > Cindy,
      >
      > Unfortunately, no, there is not. However, writing such an
      > implementation is completely trivial. You could do it in less than five
      > minutes. Just negate the value returned to you by the static Compare method
      > on string (when passing the two strings).[/color]

      Another implementation would be to simply:

      1. sort
      2. reverse

      --
      Helge Jensen
      mailto:helge.je nsen@slog.dk
      sip:helge.jense n@slog.dk
      -=> Sebastian cover-music: http://ungdomshus.nu <=-

      Comment

      Working...