using System;
using System.Collections;
public struct MyStruct
{
public int Id;
public string Name;
public MyStruct(int id, string name) {
Id = id;
Name = name;
}
}
public class Program
{
public static void Main()
{
ArrayList arrayList = new ArrayList();
arrayList.Add(new MyStruct(1, "aaa"));
arrayList.Add(new MyStruct(2, "bbb"));
arrayList.Add(new MyStruct(3, "ccc"));
arrayList.Add(new MyStruct(4, "ddd"));
// Convert ArrayList to an array of structures
MyStruct[] structArray = (MyStruct[])arrayList.ToArray(typeof(MyStruct));
foreach (var item in structArray) {
Console.WriteLine($"Id: {item.Id}, Name: {item.Name}");
}
}
}
/*
run:
Id: 1, Name: aaa
Id: 2, Name: bbb
Id: 3, Name: ccc
Id: 4, Name: ddd
*/