Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - number of elements in array

Reply
 
Old 05-25-2007   #1 (permalink)
Frank


 
 

number of elements in array

Hi,

Is there a variable that tells me how many elements there are in an array?

thanks,



My System SpecsSystem Spec
Old 05-25-2007   #2 (permalink)
Keith Hill


 
 

Re: number of elements in array

"Frank" <Frank@discussions.microsoft.com> wrote in message
news:4EA172A3-070A-465D-A100-C7AE54EB2BEE@microsoft.com...
> Hi,
>
> Is there a variable that tells me how many elements there are in an array?
>


There is a property called Length on all .NET arrays. Use like so to find
out how many elements are in the first dimension of an array:

> $arr = 1,2,3,4
> $arr.Length

4

--
Keith

My System SpecsSystem Spec
Old 05-25-2007   #3 (permalink)


 
 

Most collections use Count instead of Length. It is just one of the little inconsistencies in .NET. PowerShell provides an alias property so you can always use COUNT:

PS> $a=1,2,3,4,5
PS> $a.Length
5
PS> $a.Count
5
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Inserting or deleting elements in an array VB Script
Converting array elements between types PowerShell
Get Index Number of Array Item? PowerShell
re-ordering elements in an array? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46