Arrayはイミュータブルだが、でもどうしてもAddメソッドつけたい時
C# Add extension Append method to class array of type T - Stack Overflow
using System; public static class ArrayExtensions { public static T[] Add<T>(this T[] array, params T[] add) { for (int i = 0; i < add.Length; i++) { Array.Resize(ref array, array.Length + 1); array[array.Length - 1] = add[i]; } return array; } }
使い方
string[] array = new string[] { "Foo", "Bar" }; array = array.Add("Baz", "Foobar"); for (int i = 0; i < array.Length; i++) { Debug.Log($"{array[i]} "); }