Sorting Arrays

Element6

Well-known member
Joined
Feb 16, 2010
Messages
85
Programming Experience
5-10
Ok well .NET definately makes sorting Arrays easy. I have a quick question though if anyone knows.

I am using the Array type .Sort function to sort my array.

By default it places the result Array into Ascending order Least to Greatest

How do I change that to Descending order Greatest to Least?
and
How do I change it to Closest to logic? or does that not exist?

Assume there is an Array of Numbers 0,13,21,-2,4,5,1.34 and I want them to sort closest to 0 or some other arbitray value; the Output should look similar to:

0,1.34,-2,4,5,13,21

Is there anyway of doing this? or do I have to write the routine?
 
Not necessarily, the comparable result I get is 9 seconds ('Array length of 9999999'), which is way faster.

This is surprising. I was under the impression that the OrderBy function would create a shallow copy of the array and then call Array.Sort with a delegate function.

I'm not sure how with the added level of overhead it would actually be quicker.
 
* REVISED *

I know; but it doesn't change the fact that I use .NET to do prototype development; not actual. I use .NET for the RAD not the technology; I just like to stay current so I know the Microsoft Terms are and I happen to like the interface.

So rather then viewing the universe as designing cars for the future; it's more like saying I design cars; what they are made from doesn't matter. Because in all actuality a car can be made from plastic if the designer choose it to be and not from steel.

Managed resources is only valid on Microsoft platforms and does not port well to say unix; or some independant OS. Which my code will be moving to.

But I understand what you are saying. I prerequisited the conversation with the statement that my development WILL be ported to a different platform other then Windows. So I will not be taking advantage of certain technologies that Microsoft puts into play for reasons of, Better or Non-Compatiable solutions.

The truth is Microsoft does not direct the state of a market, they have a solid influence this is true. That does not make them the sole stake in the market trends; that has and always will be the job of the consumer until there are no more customers to buy things this will not change.

In this case particularly, Microsoft does not fit or match my independant requirements it does however make design much easier in the form of Rapid Application Development (which IS the intent and design of the .NET framework) so, I am taking full advantage of that but I need to maintain a general approach to solving the problem without being overly coupled to a Microsoft Solution.

This means that in order for me to produce a viable solution ("car") I must maintain a software development discipline which is not coupled to a particular strategy (which Microsoft has unduely, and erroroniously support that there solution is the best fit; marketing only gets you so far until you realize it's not what you need. The customer IS the judge of that, not Microsoft).

I will be using historical coding strategies and infer them where I can; in this case it is NEW development in a very different vector then what Microsoft is doing, and yes, it's also security related; so a lot of reinventing the wheel but using generic coding implementations. Microsoft has their market; this is development for stuff that Microsoft does not run on, hardware they do not code for, I know because I am the inventor and I haven't given them rights to develop for it nor will I because I have issues with making coding public and prefer to train as needed then mass market.

I appreciate your Microsoft enthusiasm. My question was .NET related; in the sense of How does .NET handle a certain criteria and what is the differential between the .NET solution and the standard old school non Object Oriented solution and benchmarked, does the .NET solution work better over the Object Oriented Solution.

Managed Threads, and Managed Resources is VERY GOOD for windows platform specific stuff. However, for lets say a homemade component that does not follow standard convention it doesn't. So, Managed Resources IS NOT an option for me. I have to redevelop some of that as it is, for a non standard solution, in this case a lot of the Managed resources is handled at a different level. I wish I could use it, because it would make my job a lot easier.
 
Last edited:
Back
Top