473,699 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array Declaration in C# use Count instead of UpperBound

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.
Nov 16 '05 #1
4 8284
So declaring the number of elements you require is counter-intuitive?

Glenn

"Annoyed Programmer" <Annoyed Pr********@disc ussions.microso ft.com> wrote in
message news:33******** *************** ***********@mic rosoft.com...
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.

Nov 16 '05 #2
Jay
"Annoyed Programmer" <Annoyed Pr********@disc ussions.microso ft.com> escreveu
na mensagem news:33******** *************** ***********@mic rosoft.com...
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.


Nov 16 '05 #3
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. :)

Nov 16 '05 #4
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
Nov 16 '05 #5

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

Similar topics

2
1744
by: William Morris | last post by:
I have a one-dimesional array of potentially thousands of items, each of which is a string of at least one up to 30 characters, mixed letters and numbers. I have another array - potentially as large - whose items I wish to find in the first array. A nested loop would answer this problem - and does for the time being. for x = 0 to ubound(secondarray) for y = 0 to ubound(firstarray) if secondarray(x) = firstarray(y) then
3
392
by: kohvirus | last post by:
Hello everyone. I'm currently trying to write a program with an array but for the life of me I can't seem to get the right syntax for the array. Here is the program as follows: #include <iostream> #include <stdio.h> void display(int A , int m, int n)
1
1728
by: freddy | last post by:
in my code I am using an array, but it only reads one like it doe not loop Dim i As Integer Dim sr As IO.StreamReader Dim strline, strlines() As String Dim fmtstr As String = "{0,-15}{1,5:n1}{2,10:n1}" sr = IO.File.OpenText("Soft Drinks.txt") strline = sr.ReadLine lstdisplay.Items.Clear() For i = 0 To upperbound strlines = strline.Split(CChar(","))
1
57853
by: Samuel R. Neff | last post by:
Are there any differences between using Array.Length and Array.GetUpperBound(0) on a one-dimensional array? We have a team of developers and most people use Array.Length but one developer uses GetUpperBound(0). I'd like the code to all be consistent but would like to know if there is any other reason I can provide to justify using only Array.Length instead of GetUpperBound(0). I read that Array.Length has special meaning to the...
6
4448
by: paul.hester | last post by:
Hi all, Does anyone know why the ViewState would be empty? When I'm receiving a postback, I can access a posted value using controlName.Value but not ViewState. I have EnableViewState set to true in my master page and content page. Thanks,
2
2995
by: lab3terch | last post by:
I am a student finishing a class in Visual Basic, and would like some assistance with a program I am working on. I need to read the contents of a file (showing makes of cars on one line and a daily rental fee on the following line) into an array and then display the file contents in a list box. The user then chooses the car he/she wants to rent. I then need to obtain the rental fee from the array and use that value to calculate the total...
11
2419
by: Bob Rock | last post by:
Hello, I have an array of strings and need to find the matching one with the fastest possible code. I decided to order the array and then write a binary search algo. What I came up with is the following. I noticed that if I set: int upper = strings.GetUpperBound(0); I never match the last element in the array (i.e. "iii")
5
6516
by: John | last post by:
How can I fill an array randomly so it contains a certian range of numbers (1 - 100 for example) ? My Goal is to generate a set of numbers in random order.
5
1812
by: latin & geek via DotNetMonster.com | last post by:
dear all, hi. i have a little sub routine which works fine in my dummy test program, but when i insert it in my main program it throws errors. this is the subroutine: Public Sub TagListing() 'adds a tag category from the tag stack into the unique tag collection
0
9172
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
9032
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...
1
8908
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7745
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...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
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
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.