C#获取List的一种方式

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 using System.Linq;
 5 
 6 public class lgs : MonoBehaviour
 7 {
 8     void Start()
 9     {
10         IEnumerable<int> test = GetIntList();
11         List<int> list = test.ToList();
12 
13         IEnumerable<GameObject> objs = GetObjList();
14         List<GameObject> objList = objs.ToList();
15 
16         foreach (var item in list)
17         {
18             Debug.Log(item);
19         }
20     }
21 
22     IEnumerable<int> GetIntList()
23     {
24         yield return 12;
25         yield return 13;
26     }
27 
28     IEnumerable<GameObject> GetObjList()
29     {
30         yield return new GameObject();
31         yield return new GameObject();
32     }
33 }

猜你喜欢

转载自www.cnblogs.com/luguoshuai/p/9952231.html
今日推荐