is it correct that I cannot assign a function to a variable - like:
$h = {ID="x1";readStream=$Null;... }
...
$h.readStream = function{ ... }
Thanks!
P.S. @ A.Wiechers: To me it would help a lot if ALL the Title has at first entry the prg.-langague the question is about!! For this question I have to open only needles hints which I would have been able to skip if e.g. "Can I assign a function to a variable for use within another function? 1" would start with "Python" - the entry of the tags do NOT filter the StackExchange-suggestions! This would even help to prevent duplicate entries just because the titles are similar!!
You just need to use a scriptblock.
let's take a really simple example : I want to multiply two integers in my function :
just do something like :
$h = @ {ID="x1" ; DoStuff = $Null }
$h.DoStuff = { $args[0] * $args[1] }
# note that $h = @{ID="x1" ; DoStuff = {$args[0] * $args[1]} } works as well
# Invoke your block :
& $h.DoStuff 6 7
# or
$h.DoStuff.Invoke(6,7)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments