省略号在PowerShell中的作用是什么?

时间:2012-08-30 21:46:05

标签: powershell

我熟悉基本的range 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}

但是,我今天意外地使用省略号(...)而不是范围运算符(..),并注意到它由于某种原因从N下降到0:

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

发生了什么事?

1 个答案:

答案 0 :(得分:12)

仍在使用范围运算符 - 事实证明,范围运算符的第二个输入(在本例中为.3)被隐式转换为整数,因为范围运算符只接受整数输入。

这可以通过使用高于.5的右侧值来验证:

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

当您使用明显非整数值作为范围运算符的右侧值时,这更容易看到:

PS C:\> 5..'3'
5
4
3
相关问题