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。其实和