473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Arrays with length of 0

Hi,

Using VB 2005, I have a function that returns an array of a certain object.
In certain cases the function should return an array with a length of 0.
I've found that this works:

Dim child(0) As Object
Array.Resize(Of Object)(child, 0)
Return child

If I leave out the middle line, it returns an array with a length of 1, the
object in the array being nothing.

I'm interested in knowing why this is the case. Why doesn't "Dim child(0)
as Object" create an array with a length of 0?

Thanks,
Nathan
Jan 2 '06 #1
3 1214
"Nathan M" <Na*****@discussions.microsoft.com> schrieb:
Using VB 2005, I have a function that returns an array of a certain
object.
In certain cases the function should return an array with a length of 0.
I've found that this works:

Dim child(0) As Object
Array.Resize(Of Object)(child, 0)
Return child

If I leave out the middle line, it returns an array with a length of 1,
the
object in the array being nothing.
\\\
Dim child(-1) As Object
///
I'm interested in knowing why this is the case. Why doesn't "Dim child(0)
as Object" create an array with a length of 0?


'Dim <variablename>(<upper bound>) As <type>'. The resulting array will
have <upper bound> + 1 elements, i.e. 'Dim child(10) As Object' will
construct an array with 11 elements with indices 0, ..., 10.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 2 '06 #2
Nathan,

The why

Dim child(0) As Object
Array.Resize(Of Object)(child, 0)
Return child

I'm interested in knowing why this is the case. Why doesn't "Dim child(0)
as Object" create an array with a length of 0?

A strange way that is chosen to keep VBNet compatible with the methods which
uses First as start index instead of Zero. (It would been great as they had
chosen for one of those, than methods as Mid and Len would not be so
confusing).

However, done is done and you can not make those decisions not done.

Cor
Jan 2 '06 #3
Dim child(0) As Object
means the same as the old vb6 style
Dim child(0 To 0) As Object

Use
Dim child(-1) As Object for 0 length

Jan 2 '06 #4

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

Similar topics

5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
2
by: Tom | last post by:
What's the best way to compare two byte arrays? Right now I am converting them to base64 strings and comparing those, as so: 'result1 and result2 are two existing byte arrays that have been...
38
by: ssg31415926 | last post by:
I need to compare two string arrays defined as string such that the two arrays are equal if the contents of the two are the same, where order doesn't matter and every element must be unique. ...
19
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
3
by: huiling25 | last post by:
I'm matching the value of each of the 2D array against 1D Array. 1D array is actually the conversion of 2D to 1D array, so that i can use Arrays.sort() to sort the array to ascending order. However...
5
by: M. Fisher | last post by:
Pardon my ignorance here... I have created arrays such as: var SDET_Lab130= new Array(); SDET_Lab130 = new Array(); SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ;...
9
by: Jack | last post by:
If I don't specify "ref" in the argument list when passing an array to the callee, I am passing the array (reference) by value. But this makes me confused because it actually means a "reference" of...
7
by: daniel | last post by:
Hello , I always had the feeling that is better to have char arrays with the size equal to a power of two. For example: char a_str; // feels ok char b_str; //feels not ok.
6
by: Emiurgo | last post by:
Hi there to everyone! I've got a problem which may be interesting to some of you, and I'd be very grateful if there is someone who can give me some advice (or maybe redirect me to some other place)....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.