- Home /
Question by
Greenwar · Apr 26, 2015 at 08:31 PM ·
c#listscriptingbasicslistsconstructors
How to initialize lists with set number of null elements?
Hey guys, I want moAudioClip and moGameObject to have 3 null elements each whenever a MoreOptions is created.
How do I do that? I've been trying some with a constructor but can't get it to work and have left it empty for now.
public class Test : MonoBehaviour {
public class MoreOptions{
public List<AudioClip> moAudioClip;
public List<GameObject> moGameObject;
public MoreOptions(){
}
}
public List<MoreOptions> moreOptionsList = new List<MoreOptions>();
}
Comment
Answer by ttesla · Jul 10, 2015 at 08:51 AM
You can't and you shouldn't because adding null element to a list is not allowed. However you can add valid 3 elements then you can set them to null. Which is very ugly though :/
Its better to change your logic.
Your answer
Follow this Question
Related Questions
Overwrite the value in my List but why? 0 Answers
Grab a specific item from a list 3 Answers
Keep list of GameObjects between scenes 2 Answers
Access list storing custom class variables from another script 1 Answer
Affect every object in array. 1 Answer