![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Stupid Array Tricks: Initializing an Array to a Certain Size Okay, so I'm trying to use the SqlDataReader.GetValues() method, and it wants me to pass it an array. The problem is that it wants the array to be at least as large as the data that I want to put it in, otherwise the data gets truncated. I whipped this up, but it doesn't seem like the most efficient way: foreach ($i in 0..($reader.FieldCount - 1)) { $row += $null } Is there a better way to gin up an empty array of a specific size (a contradiction, I know, but you know what I mean)? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Stupid Array Tricks: Initializing an Array to a Certain Size PS > $arr = new-object object[] $reader.FieldCount --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic t> Okay, so I'm trying to use the SqlDataReader.GetValues() method, and t> it wants me to pass it an array. The problem is that it wants the t> array to be at least as large as the data that I want to put it in, t> otherwise the data gets truncated. t> t> I whipped this up, but it doesn't seem like the most efficient way: t> t> foreach ($i in 0..($reader.FieldCount - 1)) { t> $row += $null t> } t> Is there a better way to gin up an empty array of a specific size (a t> contradiction, I know, but you know what I mean)? t> |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Stupid Array Tricks: Initializing an Array to a Certain Size tojo2000 wrote: Quote: > Is there a better way to gin up an empty array of a specific size (a > contradiction, I know, but you know what I mean)? Then Bruce Payette followed up with more info which was awesome, so click the link to see that. http://halr9000.com/article/430 method 1: $array = ,0 * 20 method 2: $array = @(0) * 20 -- Author, Tech Prosaic blog (http://halr9000.com) Webmaster, Psi (http://psi-im.org) Community Director, PowerShellCommunity.org Co-host, PowerScripting Podcast (http://powerscripting.net) |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Fast copy method of sub array (=array range) possible? | VB Script | |||
| Re: Dim? (array of fixed size) | PowerShell | |||
| Re: Dim? (array of fixed size) | PowerShell | |||
| RE: Dim? (array of fixed size) | PowerShell | |||
| how to assign values to array and how to create array via variable | PowerShell | |||