Domanda

I know it is possible to set mulitple variables to the same value on the same line :

$a, $b = "value"

My question is, Is it possible to do the same thing with Arrays and "+=" operators ?

I've tried this :

 $a = @()
 $b = @()
 $a, $b += "test"

But i get the following error :

Au caractère Ligne:1 : 1
+ $a, $b += test
+ ~~~~~~
L'expression d'affectation n'est pas valide. Vous devez placer un élément affectable, comme une variable ou une propriété, à gauche d'un opérateur
d'affectation.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidLeftHandSide

Thanks for your help !

È stato utile?

Soluzione

Here's one way to do it in the same line:

$a,$b | foreach {$_ += 'test'}

Edit: that actually doesn't work. This does

$a,$b = $a,$b |% {,($_ += 'test')}

Not sure if that's any better than the iex or not.......

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top