Array.Sort a Static method?

  • Thread starter Thread starter Rene \(Programmer Wannabe\)
  • Start date Start date
R

Rene \(Programmer Wannabe\)

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



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

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

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

What's the rationale?


Sam
 
Sam Sungshik Kong said:
int[] someArray = new int[3];

Array.Sort(someArray);

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 ...
 
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
..<
 
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();<
 
Yes I notice that, that why I started questioning the reason for Arrays not
to do the same thing!



Jeff Louie said:
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();<
 
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?
 
Back
Top