$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. 谷歌识图、google识图如何知道图片相似?

    转自:http://www.hahait.com/news/185.html 原理非常简单易懂.我们可以用一个快速算法,就达到基本的效果.这里的关键技术叫做“感知哈希算法”(Perceptual ha ...

  2. VS2015使用scanf报错解决方案

    版权声明:本文为博主原创文章,未经博主允许不得转载. 方法一:在程序最前面加#define _CRT_SECURE_NO_DEPRECATE: 方法二:在程序最前面加#define _CRT_SECU ...

  3. jar文件につぃて

    打包jar文件和设置class路径: 查看jar文件内容:

  4. 获取多个汉字首字母(php)

    <?php function getfirstchar($s0){ $fchar = ord($s0{0}); if($fchar >= ord("A") and $f ...

  5. C# 基础中有关术语理解

    一.栈vs堆  深入理解堆栈.堆在内存中的实现 二.Socket 深入探析c# Socket 三.多线程 c# 多线程 --Mutex(互斥锁)

  6. pl sql 无法解析指定的连接标识符

        使用PLSQL Developer时,“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法< xmlnamespace prefix ="o" ...

  7. Vue.js——webpack

    Vue.js——60分钟webpack项目模板快速入门 browserify是一个 CommonJS风格的模块管理和打包工具,上一篇我们简单地介绍了Vue.js官方基于browserify构筑的一套开 ...

  8. MySQL 二进制日志过滤

    binlog_do_db; binlog_ignore_db; 这个两个参数是用来控制对哪个数据库的更改要记录日志:下面以binlog_ignore_db为例子. 假如binlog_ignore_db ...

  9. 如何使ListView具有像ios一样的弹性

    ListView 是我们在开发过程中经常使用的控件之一,通常情况下,当我们没有对它进行自定义或者给添加headerview 或者footerView的时候,他都没有一个很好的反馈效果,但是相比较而言, ...

  10. date命令使用

    date命令的帮助信息 [root@localhost source]# date --help用法:date [选项]... [+格式] 或:date [-u|--utc|--universal] ...