473,809 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array.Sort a Static method?

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

Thank you.
Nov 16 '05 #1
7 1375
> int[] someArray = new int[3];

Array.Sort(some Array);


I am curious, too.
Here's a similar example:

Math.Abs(-3); instead of -3.Abs();

What's the rationale?
Sam
Nov 16 '05 #2

"Sam Sungshik Kong" <ss*@chol.nospa m.net> wrote in message
news:uQ******** ******@TK2MSFTN GP11.phx.gbl...
int[] someArray = new int[3];

Array.Sort(some Array);


I am curious, too.
Here's a similar example:

Math.Abs(-3); instead of -3.Abs();

What's the rationale?


Well, consider another framework to which .NET has many similarities, in
which scalars are not objects arnd arrays have no methods other than the
ones they inherit from Object. The corresponding methods there (Math.abs()
and Arrays.sort()) must be static. So if you picture that it was simpler to
follow an existing model than to think each individual decision through ...
Nov 16 '05 #3
Mike.. I must wonder if this was a conscious decision to make it easier
for
Java programmers to transition to C#.

Regards,
Jeff
Well, consider another framework to which .NET has many similarities,

in
which scalars are not objects arnd arrays have no methods other than the
ones they inherit from Object. The corresponding methods there
(Math.abs()
and Arrays.sort()) must be static. So if you picture that it was simpler
to
follow an existing model than to think each individual decision through
..<

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Rene... The framework does not seem to be consistent here in that
ArrayList
does use an instance method to Sort.

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

int[] someArray = new int[3];
someArray.Sort( );<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Yes I notice that, that why I started questioning the reason for Arrays not
to do the same thing!

"Jeff Louie" <je********@yah oo.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Rene... The framework does not seem to be consistent here in that
ArrayList
does use an instance method to Sort.

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

int[] someArray = new int[3];
someArray.Sort( );<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #6
I am guessing that this is due to the fact that two different programmers
worked on the classes. It could be the case that Microsoft don't have
internal guidelines when it comes to placing statics / instance methods?

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #7
And obviously the previous info about the java similarities ;-)

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #8

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

Similar topics

7
3270
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)
2
1593
by: Rene \(Programmer Wannabe\) | last post by:
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; 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
2514
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
4758
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
3892
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
1994
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
3774
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
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9602
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
10639
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
10376
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...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
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
5550
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
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.