配列系は勝手に参照渡しではない。一応確認。
using UnityEngine; using System.Collections; using System.Collections.Generic; public class RefTest : MonoBehaviour { // Use this for initialization void Start () { List<string> listRef = new List<string>(); listRef.Add("1"); DoRef(ref listRef); foreach(var item in listRef){ Debug.Log(item); } Debug.Log(new string ('-', 42)); List<string> listNotRef = new List<string>(); listNotRef.Add("1"); DoNotRef(listRef); foreach(var item in listNotRef){ Debug.Log(item); } } // 参照実験 void DoRef (ref List<string> list) { list.Add("2"); } // 値渡し実験 void DoNotRef (List<string> list) { list.Add("2"); } }
結果
1 2 ------------------------------------------ 1
ちゃんとなった。