CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2013
    Posts
    1

    Post how to pass an array to function and return array in asedning order

    i want to make programme in c# ,how to pass an array to function and return array in asedning order .

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: how to pass an array to function and return array in asedning order

    Instead of using a raw array, why not use a generic list collection? Then you can call .Sort() to sort the collection.

    Of course, if this is a homework assignment, then you'll have to do it manually.

  3. #3
    Join Date
    Apr 2012
    Posts
    43

    Re: how to pass an array to function and return array in asedning order

    Alternatively you can use LINQ to sort the array. IMO its the better choice because of its flexibility. You can specify a function for it to use in a transformation. Basically, you can tell it how to derive values from each element of whatever type is in the array and sort on that.
    Code:
    //
                int[] numbers=new int[]{90,1,87,78,2,3,12};
    
                numbers = numbers.OrderBy(i => i).ToArray();
    Note that you must be targeting the .Net Framework 3.5 and up to use LINQ.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured