gpt4 book ai didi

xml - PowerShell - 函数参数 - 转换数组列表?

转载 作者:行者123 更新时间:2023-12-02 23:56:31 25 4
gpt4 key购买 nike

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

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

我的意思是类似于以下 C# 声明:
void SomeMethod ( List<myCustomClass> listOfObjects) { }

我知道我可以在 foreach 中转换对象:
foreach($item in [DataBaseItem]$collectionWithItems)
{

}

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

最佳答案

我会使用 [myCustomClass[]] :

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

关于xml - PowerShell - 函数参数 - 转换数组列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44237138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com