-
August 13th, 2013, 08:36 AM
#1
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 .
-
August 16th, 2013, 04:03 PM
#2
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.
-
August 21st, 2013, 03:15 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|