두 가지 경우가 있는데 코드가 어떻게 작동하는지 알 수 없습니다. 도와주세요. 감사
사례 1 :
Transform[] zombiesTransform;
private void Start()
{
zombiesTransform = new Transform[5]; // now i have initialized so i can add some transform in it
// which is fine
}
사례 2 :
Zombie[] zombies;
private void Start()
{
zombies = FindObjectsOfType<Zombie>(); // how is this zombie array is filled with value without
// initializing zombies variable like "zombies = new Zombies[5]"
}
예제를 사용하여 설명하겠습니다 (코드를 작성하는 것처럼 FindObjectsOfType
)
public T[] FindObjectsOfType<T>() where T : new() {
T[] collection = new T[5];
T[0] = new T();
// create more T items
return T;
}
그래서 나는 여기서 무엇을하고 있는가? 제네릭 타입 T
은 새로 만들 수 있다고 말하고 있습니다 (그것의 객체를 만들 수 있습니다). 새로운 T
객체 배열을 선언하고 인스턴스화 한 다음 필요한 객체로 반환합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다