1 public class ListElementAtDemo : MonoBehaviour { 2 3 List<string> list = new List<string>(); 4 5 void Awake() 6 { 7 list.Add("aaaaaa"); 8 list.Add("bbbbbb"); 9 list.Add("cccccc"); 10 list.Add("dddddd"); 11 } 12 13 void Start () 14 { 15 Debug.Log(list.ElementAt(0)); 16 Debug.Log(list[0]); 17 } 18 19 }
兩種的打印結果都是 aaaaaa 。 但是ElementAt 這個方法,需要導入 using System.Linq; 這個命名空間
打印結果是 aaaaaa。其實和