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 - Passing ArrayList as reference to function

Reply
 
Old 01-09-2008   #1 (permalink)
RD


 
 

Passing ArrayList as reference to function

I'm trying to pass ArrayList as [ref] to a function without any success. I
tried .Add which fails because [ref] deosn't have Add method. I tried casting
but to no avail. Does any one have any sample code? thanks.

My System SpecsSystem Spec
Old 01-09-2008   #2 (permalink)
Kirk Munro [MVP]


 
 

Re: Passing ArrayList as reference to function

function RefTest {
param(
[REF]$refVar
)

$refVar.Value = 1

}

$intVar = 0
"`$intVar = $intVar"
RefTest ([REF]$intVar)
"`$intVar = $intVar"

--
Kirk Munro [MVP]
Poshoholic
http://poshoholic.com


"RD" <RD@xxxxxx> wrote in message
news:B280F97F-5ECF-4CA9-BF2C-6704F51AC00D@xxxxxx
Quote:

> I'm trying to pass ArrayList as [ref] to a function without any success. I
> tried .Add which fails because [ref] deosn't have Add method. I tried
> casting
> but to no avail. Does any one have any sample code? thanks.

My System SpecsSystem Spec
Old 01-09-2008   #3 (permalink)
Kirk Munro [MVP]


 
 

Re: Passing ArrayList as reference to function

To follow up on your specific issue, you probably need to do
$myRefVar.Value.Add inside your function to get it to work. When working
with reference variables, you need to use .Value to get the actual variable
that is being referenced so that you can call methods, assign values, etc.

--
Kirk Munro [MVP]
Poshoholic
http://poshoholic.com


"RD" <RD@xxxxxx> wrote in message
news:B280F97F-5ECF-4CA9-BF2C-6704F51AC00D@xxxxxx
Quote:

> I'm trying to pass ArrayList as [ref] to a function without any success. I
> tried .Add which fails because [ref] deosn't have Add method. I tried
> casting
> but to no avail. Does any one have any sample code? thanks.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Thread-safety: Change property of items in arraylist versus removingitems from the arraylist .NET General
Passing dataset by reference between forms, what is the best approach? .NET General
Passing hash table by reference PowerShell
Passing arguments to a function PowerShell
passing variable by reference 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