Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

number of elements in array

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-25-2007   #1 (permalink)
Frank
Guest


 

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
Guest


 

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)
Newbie


Join Date: May 2007
 
Rep Power: 11
jsnover is on a distinguished road
  jsnover is offline

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting array elements between types Kryten PowerShell 6 03-01-2008 12:25 PM
Support for Adobe photoshop elements 5 or premier elements 3 on Vista 64 bits Sébastien DELAYRE Vista General 5 03-26-2007 09:57 AM
Get Index Number of Array Item? ydroam PowerShell 8 12-18-2006 12:46 PM
Get Index Number of Array Item? ydroam PowerShell 0 12-15-2006 10:59 AM
re-ordering elements in an array? Marco Shaw PowerShell 7 11-10-2006 04:25 PM


Vistax64.com 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 2005-2008

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 47 48 49 50 51