ニュース

Top  >   15. C#とMonoBehaviour  >   Q, リスト(List)に要素を追加・削除したい

Q, リスト(List)に要素を追加・削除したい

2026/03/19

メインコンテンツへスキップ
< すべてのカテゴリに戻る

A,結論

List<T> を使い、Add、Remove、RemoveAt などで操作します。

サンプルコード

using System.Collections.Generic;
using UnityEngine;

public class ListExample : MonoBehaviour
{
    private readonly List<string> itemList = new();

    private void Start()
    {
        itemList.Add("Apple");
        itemList.Add("Banana");
        itemList.Remove("Apple");

        Debug.Log($"要素数: {itemList.Count}");
    }
}

※ 実機確認が必要な項目は、Editor だけで判断せず、対象デバイスでも必ず動作確認してください。

難易度:Level 2(初心者)
対象プラットフォーム:PC,Visual Studio,Unity
関連キーワード:C#,削除,リスト,aca

Level 1-2 向けバナーLevel 3-5 向けバナー 1Level 3-5 向けバナー 2