【问题标题】:PowerShell - parametrs of function - casting arraylist?PowerShell - 函数参数 - 转换数组列表?
【发布时间】:2017-05-29 15:49:59
【问题描述】:

我有我的自定义类的对象的 Arraylist。 怎么说函数param就是这个类的ArrayList?

function CreateArrays{
param(
[System.Collections.ArrayList] $collectionWithItems
)
}

我的意思类似于以下 C# 声明:

void SomeMethod ( List<myCustomClass> listOfObjects) { }

我知道我可以在 foreach 中投射对象:

foreach($item in [DataBaseItem]$collectionWithItems)
{

}

但是有没有办法在params中说出来?

【问题讨论】:

    标签: xml powershell


    【解决方案1】:

    我会使用[myCustomClass[]]:

    function CreateArrays{
    param(
    [myCustomClass[]] $collectionWithItems
    )
    }
    

    【讨论】:

    • 当我使用这个时我有以下错误:在 C:\ps\DbConfiguration\dbscript3.ps1:99 char:2 + [[DataBaseItem[]] $collectionWithItems + ~ Missing type name after '[ '。
    • 你有两个领先的[[
    • 我不这样做,但我必须等待几分钟:P
    猜你喜欢
    • 1970-01-01
    • 2015-04-02
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-28
    • 2010-11-28
    • 2016-05-24
    相关资源
    最近更新 更多