$newArray = @()
$newArray.Add("Hello")

  

If I create a new array, and using the method Add(). Windows PowerShell will tell me :

Exception calling "Add" with "1" argument(s): "Collection was of a fixed size."

Reason:

When you use the $array.Add() method, you're trying to add the element into the array. An array is a collection of fixed size, so you will recieve an error.

So, what should I do ?

Solution 1:

$successfulArray = New-Object System.Collections.Generic.List[System.Object]

$successfulArray.Add("Hello")
$successfulArray.Add("World") # When you need array, you can transfer like:
$successfulArray.ToArray()

  

Also a more simple solution 2:

$easyArray = @()
$easyArray += "Hello"
$easyArray += "World"

  PS creates a NEW array with the same elements as $array+ the one(s) you're adding, and then it overwrites the original.

Array.Add () and += in PowerShell的更多相关文章

  1. 448. Find All Numbers Disappeared in an Array Add to List

    题目描述 题目分析 有个[1,n]的条件要充分利用起来. 题目代码 public class Solution { public List<Integer> findDisappeared ...

  2. 使用powershell提权的一些技巧

    原文:http://fuzzysecurity.com/tutorials/16.html 翻译:http://www.myexception.cn/windows/1752546.html http ...

  3. [PowerShell] 快速入门, 基本语法, 常用类型, 函数, .NET 互操作

    PowerShell 快速入门 开始之前, 我们认定你已经有一定的编程基础, 熟悉 .NET 中的类型与对象. 此文章对于 .NET 开发者来说更简单哦! 在 PowerShell 中, 几乎一切都是 ...

  4. 作为平台的Windows PowerShell(一)

    除了作为一种脚本语言外,Windows PowerShell被多种应用程序使用.这是因为Windows PowerShell引擎可以被托管在一个应用程序内部.这篇博文和下一篇博文将会处理在C#应用程序 ...

  5. [置顶] Array ArrayList LinkList的区别剖析

    这是一个面试中我们经常被问到的问题 Array.ArrayList.LinkList之间的区别:Array.ArrayList.LinkList均属于泛型的范畴,都用来存放元素,主要区别是Array是 ...

  6. Powershell创建数组

    在Powershell中创建数组可以使用逗号. PS C:Powershell> $nums=2,0,1,2 PS C:Powershell> $nums 2 0 1 2 对于连续的数字数 ...

  7. LeetCode 525. Contiguous Array

    525. Contiguous Array Add to List Description Submission Solutions Total Accepted: 2476 Total Submis ...

  8. PowerShell 字符串操作--转载

    格式化操作符 –F 在PowerShell文本操作符中非常重要,经常被用来增强数字类型和日期类型的可读性: "{0} diskettes per CD" -f (720mb/1.4 ...

  9. 9.1 ArrayList(集合)的使用,与array(数组)的对比

    1.array 和ArrayList的区别? array 数组的长度是固定的,适应不了变化的需求. ArrayList集合的长度可变.大小可变. 2.为什么要用集合,它优点是什么? java是面向对象 ...

随机推荐

  1. Oracle基础(二)---操作命令

    接上篇博客介绍Oracle基本概要.以下将介绍数据库的操作指令. Sql*plus经常使用命令 连接命令 1. conn[ect] 使用方法 connusername/password@网路服务名[a ...

  2. 遍历GridView

    ].Text+"--------------");                }            }

  3. 学会用这二个键,你就是电脑高手了,一个是Win键,另一个是Ctrl!

    学会用这二个键,你就是电脑高手了,一个是windows键,另一个是Ctrl键. 一.windows键 1. 很多时候,需要离开座位去做别的事情,如果对自己的电脑安全很重视,不妨按住windows键后, ...

  4. C#经典之Application.DoEvents()的使用

    最近做了一个文件上传的模块,因为牵扯到电脑文件的扫描,想做一个实时显示当前扫面文件的功能,就类似于360文件扫描时的效果,本来打算用多线程来实现,但是方法太多没有实现,后来在程序中进行控制,由于文件太 ...

  5. 对Spring from中日期显示格式化问题

    开始时间 结束时间 保存 取消 想在input中让日期格式显示为HH:ss 但是各种百度没有找到答案 最后Google之 http://stackoverflow.com/questions/1173 ...

  6. R与数据分析旧笔记(十二)分类 (支持向量机)

    支持向量机(SVM) 支持向量机(SVM) 问题的提出:最优分离平面(决策边界) 优化目标 决策边界边缘距离最远 数学模型 问题转化为凸优化 拉格朗日乘子法--未知数太多 KKT变换和对偶公式 问题的 ...

  7. 我的Fedora22美化日记

    首先我说一下,我命令是乱打的[不要打我],用之前先google 配置RPMFusion仓库 $ sudo dnf install --nogpgcheck http://download1.rpmfu ...

  8. ODI学习笔记2--ODI产品架构

    ODI学习笔记2--ODI产品架构 ODI产品架构: ODI提供了以下几种管理工具:Designer 用于定义数据转换逻辑,这是最常用的开发工具,大部分的开发任务,包括data store的定义,in ...

  9. 10_Segue Example

    10 // // ViewController.swift // Segues Example // // Created by ZC on 16/1/10. // Copyright © 2016年 ...

  10. [转贴]JavaScript中Array(数组)的属性和方法

    数组有四种定义的方式 使用构造函数:var a = new Array();var b = new Array(8); var c = new Array("first", &qu ...