Array Declaration in C# use Count instead of UpperBound

G

Guest

Maybe this question has been addressed before, but I just stumbled with the
issue so I'll post it here.

Since I can remember array declaration in any language I've
worked(Basic/VB/VB.NET/C/C++) was:

(Example in Basic-way)

Dim Arr('UpperBound') as Type
Ex. Dim Arr(0) as String gives you a String Array with 1 element

But in C# string arr[0] gives you 0 elements, meaning the syntax is now

Type Arr('Count');

I'll like to know who though it would be a wonderful thing to break the
natural flow of thought by doing this in C# while all the remaining .NET
languages (with the possible exception of J# which I haven't tried) use the
UpperBound declaration type.

To me declare an array using count just seems counter-intuitive, maybe it's
just me.

Would like to hear your comments, for me this is an issue which should be
corrected.
 
J

Jay

Annoyed Programmer said:
Maybe this question has been addressed before, but I just stumbled with
the
issue so I'll post it here.

Since I can remember array declaration in any language I've
worked(Basic/VB/VB.NET/C/C++) was:
Wrong.
C/C++/Java use the number of elements.
(Example in Basic-way)

Dim Arr('UpperBound') as Type
Ex. Dim Arr(0) as String gives you a String Array with 1 element

But in C# string arr[0] gives you 0 elements, meaning the syntax is now

Type Arr('Count');

I'll like to know who though it would be a wonderful thing to break the
natural flow of thought by doing this in C# while all the remaining .NET
languages (with the possible exception of J# which I haven't tried) use
the
UpperBound declaration type.

To me declare an array using count just seems counter-intuitive,

maybe it's > just me.
I think so.
Would like to hear your comments, for me this is an issue which should be
corrected.
No way.
 
B

Bruce Wood

The only language that declares arrays the way you state is VB. So,
what you're really asking is why don't all of the other languages in
..NET change to conform to the way VB does things.

So, yes: I think it's just you. :)
 
C

Cor Ligthert

Annoyed Programmer

When this should be corrected it should in my opinion be in VB.

It is in my opinion crazy that

dim a(1) as string gives an array of 2 strings and that while that is the
only place it is done like that.

The problem is probably in the indexing. In VB is tried to start the
indexing in the more for people logical One, in the same way as we learn to
count.

In the C derived languages is not made direct the conversion from the
register Zero to the Human One, that legacy will probably never be solved.

(By the way I find One more logical however would be a while in big problems
when that would be done, because I am as well very much used to that
counting from Zero and than every time to subtract 1).

Just my thought,

Cor
 

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

Top