powershell 中数组的正确语法是什么?
示例1:
注2:逗号也用在 数组 {0,-30} 中的分隔项
示例 2:
为了创建一个数组,我们创建一个 变量并分配数组。数组 用“@”符号标注。让我们 采取上面的讨论并使用 阵列连接到多个远程 计算机:$strComputers = @(“服务器1”,“服务器2”,“服务器3”)
那么,哪个是正确的或者有什么区别?
Example1:
Note 2: The comma is also used so
separate items in an array {0,-30}
Example2:
To create an array, we create a
variable and assign the array. Arrays
are noted by the “@” symbol. Let’s
take the discussion above and use an
array to connect to multiple remote
computers: $strComputers =
@(“Server1″, “Server2″, “Server3″)
So, which one is correct or what is the difference ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
示例 2 使用数组转换语法,例如,它允许将单个元素视为数组:
本质上,它允许将括号之间的任何内容视为数组,包括其他命令的输出:
或者,您可以只创建一个通过指定逗号分隔列表来数组:(
不需要大括号)
Example 2 uses the array cast syntax which allows a single element, for example, to be treated as an array:
Essentially, it allows anything between the parenthesis to be treated as an array including the output from other commands:
Alternatively you can just create an array by specifying a comma separated list:
(The curly brackets are not needed)
您还可以通过将 , 运算符添加到单个值来获得单个元素数组:
You can also attain a single element array by prepending the , operator to a single value: