473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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(someArray);

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 1560
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***************@tk2msftngp13.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(someArray);

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(someArray);

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(imagine 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
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)) ...
7
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
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...
5
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...
5
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...
3
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...
6
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...
2
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.