PC Review


Reply
Thread Tools Rate Thread

Arrays with length of 0

 
 
=?Utf-8?B?TmF0aGFuIE0=?=
Guest
Posts: n/a
 
      2nd Jan 2006
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
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      2nd Jan 2006
"Nathan M" <(E-Mail Removed)> 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/>

 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      2nd Jan 2006
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


 
Reply With Quote
 
doker0@wp.pl
Guest
Posts: n/a
 
      2nd Jan 2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arrays of Multidimensional Arrays? barmy_mad@yahoo.co.uk Microsoft C# .NET 9 22nd Mar 2006 12:15 AM
Arrays of Multidimensional Arrays? barmy_mad@yahoo.co.uk Microsoft C# .NET 0 21st Mar 2006 09:09 PM
Arrays of Multidimensional Arrays? barmy_mad@yahoo.co.uk Microsoft C# .NET 0 21st Mar 2006 09:09 PM
arrays in arrays jacob Microsoft Excel Programming 4 29th Aug 2004 08:40 PM
Rectangular arrays Vs. multidimensional arrays. Nikhil Patel Microsoft C# .NET 2 21st Jul 2003 02:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:35 AM.