gpt4 book ai didi

c# - 如何将 ArrayList 转换为结构数组?

转载 作者:太空狗 更新时间:2023-10-29 23:12:06 26 4
gpt4 key购买 nike

我这里有:

Public Structure MyStruct
Public Name as String
Public Content as String
End Structure

Dim oStruct as MyStruct = New MyStruct()
oStruct.Name = ...
oStruct.Content = ...

Dim alList as ArrayList = new ArrayList()
alList.Add(oStruct)

我想将 ArrayList 转换为 MyStruct 类型的静态强类型数组。我怎样才能做到这一点?我没有使用 ToArray。

我正在使用 .NET Framework 2.0。

最佳答案

您必须转换 ToArray 的结果

MyStruct[] structs = (MyStruct[]) alList.ToArray(typeof(MyStruct));

关于c# - 如何将 ArrayList 转换为结构数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/188184/

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