Why the size of an array is a signed type?

  • Thread starter Thread starter Marco Segurini
  • Start date Start date
M

Marco Segurini

Hi,

I am wondering why the size of { array, array-list, ... } is a signed
type instead of an unsigned type.

TIA.
Marco.
 
I am wondering why the size of { array, array-list, ... } is a signed
type instead of an unsigned type.

Because uint is not CLS compliant, and the BCL classes like Array have to be
usable from all languages, including those that do not support unsigned ints.


Mattias
 
I believe that this is primarily because unsighed types are not CLS
compliant, so there is no guarantee that a particular language will support
them (it is entirely optional, and a language can still call itself .NET
compatible without them) - and so these fundamental types would be unusable.
C# does support unsigned types, byt others (VB.NET? Can't remember 100%) do
not.

For this reason, you should usually try to avoid putting non-CLS-compliant
types into your public interface; if you put a CLSCompliant attribute (true)
against your assembly, the IDE will then provide a warning whenever you do
this, unless you put in a second attribute (false) against the relevant
method (or whatever) - this makes is very easy to track what is/isn't
CLS-compliant.

Marc
 
CLS compliance. Either that or the devs were reading a bit too much Hawking.
:-)
(yes, that is obscure)

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***********************************************
Think Outside the Box!
***********************************************
 
Marco Segurini said:
Hi,

I am wondering why the size of { array, array-list, ... } is a signed type
instead of an unsigned type.

TIA.
Marco.

1. CLS compliancy, as correctly stated by the other repliers.
2. The size of an 'object' on the GC heap which is limitted to 2GB , this is
true for both 32 bit and 64 bit versions of the CLR. That means that the
largest array can only have 2^31 elements (minus a few bytes) anyway.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top