定義類別 `User` 並建立陣列:
public class User
{
private string _name;
public string Name { get => _name; set => _name = value; }
}
class Program
{
static void Main()
{
User[] users = new User[2];
var u = new User { Name = "Beniao" };
users[0] = u;
Console.WriteLine(users[0].Name); // Beniao
}
}

實務較少用,簡述:
.NET 集合分類:
| 分類 | 命名空間 | 代表類別 | 特點 |
|---|---|---|---|
| 非泛型 | System.Collections | ArrayList, Queue, Stack, Hashtable | 元素為 object,需裝箱 |
| 泛型 | System.Collections.Generic | List<T>, Dictionary<K,V>, HashSet<T>, Queue<T> | 型別安全、無裝箱、效能佳 |
| 並行 | System.Collections.Concurrent | ConcurrentDictionary, ConcurrentQueue, BlockingCollection | 執行緒安全 |
| 不可變 | System.Collections.Immutable | ImmutableList, ImmutableDictionary | 執行緒安全、函數式風格 |
依操作需求選擇介面:
公開 API 盡量回傳介面而非具體類別,保留實作彈性。