473,799 Members | 3,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

REPOST: Array.Sort a Static method?

Sorry for reposting this question, I asked this a couple of days ago but got
no definite answer as to why the Array class behaves this way. Hope this
time I will have better luck. Please read below:
Why do I have to resort to using the static method of the array like this:

int[] someArray = new int[3];
Array.Sort(some Array);

Why wasn't the Sort method for the array implemented like this:

int[] someArray = new int[3];
someArray.Sort( );

There are other classes that behave the same way and just curios to know the
reason behind this. Thank you.
Nov 16 '05 #1
2 1592
The Sort method of the Array class is only available as a static method, not
an instance method. If you are asking why the FCL implementers decided to
use a static method I believe the answer would be that it is more versatile,
but you would have to ask them.

Thomas P. Skinner [MVP]

"Rene (Programmer Wannabe)" <aa*@bbb.com> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
Sorry for reposting this question, I asked this a couple of days ago but
got no definite answer as to why the Array class behaves this way. Hope
this time I will have better luck. Please read below:
Why do I have to resort to using the static method of the array like this:

int[] someArray = new int[3];
Array.Sort(some Array);

Why wasn't the Sort method for the array implemented like this:

int[] someArray = new int[3];
someArray.Sort( );

There are other classes that behave the same way and just curios to know
the reason behind this. Thank you.

Nov 16 '05 #2
>
int[] someArray = new int[3];
Array.Sort(some Array);

Why wasn't the Sort method for the array implemented like this:

int[] someArray = new int[3];
someArray.Sort( );
I suspect this may have something to do with the way arrays actually work.
This isn't definitive as I didn't write the class, but it seems quite
logical.

For single dimension, zero based arrays, the runtime provides instructions
to manipulate them(ldelem*, stelem*, etc), whereas non zero based and
multi-dimensional arrays are used by calling methods on the Array
class(GetValue and SetValue, the compiler does this transformation for you).

Array.Sort is only capable of operating on single dimensional arrays(and
probably zero based as well) and therefore does not provide functinoality
that can be used in all arrays and does not apply as an Array instance
method.
There are other classes that behave the same way and just curios to know
the reason behind this. Thank you.


What other classes do you mean?

Some like Math make sense, because adding the entire set of methods to
simple numbers would be annoying(imagin e int have 300 methods), I'm curious
about what others you mean.
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3267
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) CType(local4, Short) = CType(src, Short)
7
1374
by: Rene \(Programmer Wannabe\) | last post by:
Why do I have to resort to using the static method of the array like this: int someArray = new int; Array.Sort(someArray);
6
1655
by: CodeRazor | last post by:
My array is int list = new int{20,99,6}; Using a for-loop, how can I order the output of this array. I don't want to use a sorted list. I know this is straightforward but can't figure it out. thank you!
5
2844
by: Jan Smith | last post by:
I've searched the overloads for the Array.Sort method, and I haven't found a clear answer to my question. Maybe it's not in Array.Sort. Here's the question: I initialize an array X with the values 28 142 3 17 225. I can sort this array in ascending order and it will return 3 17 28 142 225. But I want a method that will return the sort order, not the array in sorted
5
2508
by: Stephen3776 | last post by:
I am doing an inventory control progam and trying to output a multiple array, I am getting an illegal conversion error java.lang.double !d. Can somebody tell me what I am doing wrong or if there is another way? /* * Main.java * * Created on April 29, 2007, 6:57 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */
3
4753
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display an array of objects using a GUI. My instructions are that the CD class and it's sublcass don't need to change I just need to modify class CDInventory to include the GUI. I'm not even sure if the way I've written this is going to work but anyway, I keep getting a compilation error that says: C:\Documents and Settings\Sam\GUICDInventory.java:22: cannot find symbol symbol : constructor JList(CDInventory) location: class...
6
3886
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the examples I've seen are creating the information that will be displayed from scratch, while I have to use my previously created classes and add a GUI to it. I'm trying to do this GUI using JLabels but it won't let me refer to my CD class methods that...
2
1992
by: AZRebelCowgirl73 | last post by:
Ok I think I have added the bubbleSort methods correctly I am not getting any errors and the program runs as if I had not added them yet! My question is this! how would I now in the main method implement the shortBubble() so that it could sort the array? Here is my code! import java.lang.*; import java.util.*; import java.io.*; import ch10.*; public class ContestManagement {
2
3767
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of the 13 fields for that contact. when you double click the contact i want it to pop up and show all 13...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.