What does an ellipsis do in PowerShell?

I am familiar with the main operator:

.. Range operator Represents the sequential integers in an integer array, given an upper and lower boundary. 1..10 10..1 foreach ($a in 1..$max) {write-host $a} 

However, I accidentally used an ellipsis ( ... ) instead of a range operator ( .. ) today and noticed that for some reason it listed from N to 0:

 PS C:\> 5...3 5 4 3 2 1 0 

What's happening?

+6
source share
1 answer

The range operator is still used - as it turned out, the second input (in this case, .3 ) is implicitly cast to the range operator as an integer, since the range operator accepts only integers as input.

This can be verified using the right value above .5 :

 PS C:\> 5...6 5 4 3 2 1 

This is much easier to see when you use an explicitly non-integer value as the right value for the range operator:

 PS C:\> 5..'3' 5 4 3 
+12
source

Source: https://habr.com/ru/post/924214/


All Articles