Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to get the size of an array?

Reply
Thread Tools

How to get the size of an array?

 
 
Shapper
Guest
Posts: n/a
 
      05-24-2005
Hello,

I have this for loop:

For i = 1 to 10
....
Next

I want to use the size of an array instead of 10.

How to determine the size of an array?

Thanks,
Miguel

 
Reply With Quote
 
 
 
 
Mythran
Guest
Posts: n/a
 
      05-24-2005

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I have this for loop:
>
> For i = 1 to 10
> ...
> Next
>
> I want to use the size of an array instead of 10.
>
> How to determine the size of an array?
>
> Thanks,
> Miguel
>


Dim myArray As String() = New String() { "This", "is", "a", "string",
"array" }

For i = 0 To myArray.GetUpperBounds(0)
' Do something.
Next

NOTE: Can't remember if GetUpperBounds returns a 0 based index...it
probably does so you may need myArray.GetUpperBounds(0) - 1 instead.

Mythran

 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      05-25-2005
For i = 0 to UBound(MyArray)-1
....
Next

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I have this for loop:
>
> For i = 1 to 10
> ...
> Next
>
> I want to use the size of an array instead of 10.
>
> How to determine the size of an array?
>
> Thanks,
> Miguel
>



 
Reply With Quote
 
Egghead
Guest
Posts: n/a
 
      05-25-2005
hmmm, I think "Ubound" no need to -1

Egghead
"Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> For i = 0 to UBound(MyArray)-1
> ...
> Next
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
>
> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
> news:(E-Mail Removed)...
> > Hello,
> >
> > I have this for loop:
> >
> > For i = 1 to 10
> > ...
> > Next
> >
> > I want to use the size of an array instead of 10.
> >
> > How to determine the size of an array?
> >
> > Thanks,
> > Miguel
> >

>
>



 
Reply With Quote
 
Craig Deelsnyder
Guest
Posts: n/a
 
      05-25-2005
Shapper wrote:
> Hello,
>
> I have this for loop:
>
> For i = 1 to 10
> ...
> Next
>
> I want to use the size of an array instead of 10.
>
> How to determine the size of an array?
>
> Thanks,
> Miguel
>


myArray.Length

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      05-25-2005
I think you do need it.
it's zero based.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"Egghead" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> hmmm, I think "Ubound" no need to -1
>
> Egghead
> "Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> For i = 0 to UBound(MyArray)-1
>> ...
>> Next
>>
>> --
>> I hope this helps,
>> Steve C. Orr, MCSD, MVP
>> http://SteveOrr.net
>>
>>
>> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
>> news:(E-Mail Removed)...
>> > Hello,
>> >
>> > I have this for loop:
>> >
>> > For i = 1 to 10
>> > ...
>> > Next
>> >
>> > I want to use the size of an array instead of 10.
>> >
>> > How to determine the size of an array?
>> >
>> > Thanks,
>> > Miguel
>> >

>>
>>

>
>



 
Reply With Quote
 
Egghead
Guest
Posts: n/a
 
      05-25-2005
When you use the ubound(array) in VB.net, it gives you the upper index of
the array, nothing to do with Zero based. such as
dim a as string() = {"A","B","C","D","E"}
ubound(a) will give you 4, same as in VB 6.0. Therefore, just to know the
size, it is better to use the length. It gives you 5. Just remember to "-1"
when you use it in a loop.

Do you get your mcsd in C#?

Egghead

"Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I think you do need it.
> it's zero based.
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
>
> "Egghead" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > hmmm, I think "Ubound" no need to -1
> >
> > Egghead
> > "Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> For i = 0 to UBound(MyArray)-1
> >> ...
> >> Next
> >>
> >> --
> >> I hope this helps,
> >> Steve C. Orr, MCSD, MVP
> >> http://SteveOrr.net
> >>
> >>
> >> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
> >> news:(E-Mail Removed)...
> >> > Hello,
> >> >
> >> > I have this for loop:
> >> >
> >> > For i = 1 to 10
> >> > ...
> >> > Next
> >> >
> >> > I want to use the size of an array instead of 10.
> >> >
> >> > How to determine the size of an array?
> >> >
> >> > Thanks,
> >> > Miguel
> >> >
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      05-25-2005
You are right.
I was confusing it with Array.Length, in which case the "-1" should be used.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"Egghead" <(E-Mail Removed)> wrote in message
news:%23Osy4%(E-Mail Removed)...
> When you use the ubound(array) in VB.net, it gives you the upper index of
> the array, nothing to do with Zero based. such as
> dim a as string() = {"A","B","C","D","E"}
> ubound(a) will give you 4, same as in VB 6.0. Therefore, just to know the
> size, it is better to use the length. It gives you 5. Just remember to
> "-1"
> when you use it in a loop.
>
> Do you get your mcsd in C#?
>
> Egghead
>
> "Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> I think you do need it.
>> it's zero based.
>>
>> --
>> I hope this helps,
>> Steve C. Orr, MCSD, MVP
>> http://SteveOrr.net
>>
>>
>> "Egghead" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > hmmm, I think "Ubound" no need to -1
>> >
>> > Egghead
>> > "Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> For i = 0 to UBound(MyArray)-1
>> >> ...
>> >> Next
>> >>
>> >> --
>> >> I hope this helps,
>> >> Steve C. Orr, MCSD, MVP
>> >> http://SteveOrr.net
>> >>
>> >>
>> >> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
>> >> news:(E-Mail Removed)...
>> >> > Hello,
>> >> >
>> >> > I have this for loop:
>> >> >
>> >> > For i = 1 to 10
>> >> > ...
>> >> > Next
>> >> >
>> >> > I want to use the size of an array instead of 10.
>> >> >
>> >> > How to determine the size of an array?
>> >> >
>> >> > Thanks,
>> >> > Miguel
>> >> >
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
how does size get passed into new( size ) ? Pallav singh C++ 2 04-07-2009 04:59 PM
Preferred Size, Minimum Size, Size Jason Cavett Java 5 05-25-2008 08:32 AM
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
Dynamic Size for Text Box - Expanding more than the relative size Madhanmohan S ASP .Net 5 09-03-2004 06:28 AM



Advertisments