性能优化:foreach循环
由于使用foreach循环最终会在调用期间产生不必要的堆内存分配。可以使用但不推荐使用
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/** Author:W* 循环遍历*/
public class ForeachTest : MonoBehaviour {// Use this for initializationvoid Start () {//会在堆上分配一个Enumerator类对象,产生一些消耗foreach (Transform child in transform){if (child != null){}}for (int i = 0; i < transform.childCount; i++){Transform child = transform.GetChild(i);if (child != null){}}}// Update is called once per framevoid Update () {}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
