用数组c#遍历字典

时间:2017-03-10 06:23:06

标签: c# unity3d

我有一个以gameobjects作为键的词典,这是n量和gameobjects作为值,这可能是4的数量。

passenger = Passenger.where("DATE(created_at) = ?", Date.yesterday)

如何迭代"值?" ...还有更合适的'做我想瞄准的方式?

3 个答案:

答案 0 :(得分:0)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form>
  <input type="text" id="name" placeholder="Name">
  <input type="button" class="add-row" value="Add Row">
</form>
<table id="tab">
  <thead>
    <tr>
      <th>Name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Peter Parker</td>
    </tr>
  </tbody>
</table>
<button type="button" class="delete-row">Delete Row</button>
<button type="button" class="bttn">show Row</button>

在你的AddPole函数中尝试。

答案 1 :(得分:0)

你应该如何封装......没有统一的运行,所以可能是一些错别字。

public class FloorManager:MonoBehaviour
    {
        public gameObject floorPrefab;

        private List<Floor> floors;

        void Start()
        {
            floors = new List<Floor>();
        }

        public void AddFloor()
        {
            //instantiate prefab // gameObject floorGo = Instantiate....
            Floor floorScript = floorGo.getComponent<Floor>();
            floors.Add(floorScript);
            floorScript.AddPoles();

        }

        public void RemoveFloor(Floor floor)
        {
            floors[floors.IndexOf(floor)].gameObject.Destory();
            floors.Remove(floor);
        }
    }

    public class Floor : MonoBehaviour
    {

        public gameObject polePrefab;

        public Pole [] poles = new Pole[4];

        public void AddPoles()
        {
            for (int i = 0; i < 4; i++)
            {
                //instantiate prefab // gameObject poleGo = Instantiate....

                Pole poleScript = poleGo.getComponent<Pole>();
                poles[i]=poleScript;
            }
        }

    }

    public class Pole : MonoBehaviour
    {
        //some logic here if needed...Destroy...Damage...
    }

答案 2 :(得分:0)

使用枚举器:D玩得开心

public void AddPole(GameObject floor, GameObject pole)
    {
        var enumerator = polesAttachedToFloor.GetEnumerator ();
        for (int i = 0; i <= 4; i++)
        {
            if (enumerator.MoveNext ()) {
                var item = enumerator.Current;
            }
        }

    }