This question has already been answered:
- Are the correct answers written in the book? 3 answers
I am studying C # and Unity, the question arose.
Suppose we create an empty array with a fixed volume. Then assign the value to the array element.
Question: Why is the assignment incorrect to do outside the Start method?
That is why it is so correct:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChaikaLetit : MonoBehaviour { string[] names = new string[5]; // Use this for initialization void Start () { names [0] = "Jessie"; print ("First name is "+names[0]); } } And so no:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChaikaLetit : MonoBehaviour { string[] names = new string[5]; names [0] = "Jessie"; // Use this for initialization void Start () { print ("First name is "+names[0]); } } Thanks a lot in advance!
string[] names = new string[]{"Jessie"};this is not considered to be “using” an already created field, so correctly, right? - Rumata