15

I am not to familar with powershell. I am trying to do something that would be a single line of code in C# but in powershell it is a pain :(

In the three lines below wow3 throws an error. Anyone know why wow3 throw a type not found error? Does this syntax for delegates only work for built in types?

$wow1 =[System.Action[int]]
$wow2 =[MyType]
$wow3 =[System.Action[MyType]]
user1985513
  • 481
  • 1
  • 4
  • 13

1 Answers1

45

This line of PowerShell:

$wow1 = [System.Action[int]]

is equal to this line of C#:

var d = typeof(System.Action<int>);

That is, $wow1 contains a System.RuntimeType. Is that really what you are trying to do?

Perhaps you want something like this instead?

C:\PS> [Action[int]]$action = {param($i) Write-Host "i is $i"}
C:\PS> $action.Invoke(10)
i is 10
Keith Hill
  • 194,368
  • 42
  • 353
  • 369