- Home /
Lists (C#)
I've been trying to create a list, and even when I just copy/paste the variable declaration from someone's code here on the Answers or the forums I get this error:
The type or namespace name 'List 1' Could not be found. Are you missing an assembly reference or directive?
Which doesn't make sense because people used the exact same code I did and didn't get this error. What am I doing wrong here?
public List<Transform> myList = new List<Transform>();
Answer by Bunny83 · Jul 13, 2012 at 10:53 PM
Just add:
using System.Collections.Generic;
at the top. See the MSDN docs for more information.
edit
alternatively you could always use the full classname, however that looks a bit strange:
public System.Collections.Generic.List<Transform> myList = new System.Collections.Generic.List<Transform>();
That's why the using directive has been invented.
edit
Just in case a UnityScript user comes across, in UnityScript (Unity's Javascript) you have to use the "import" keyword instead:
import System.Collections.Generic;
Did you guys manage to use this with $$anonymous$$onoDevelop's debugger? when trying to see the contents of the Lists in the Locals inspector, it shows as "$$anonymous$$ Type ' System.Collections.Generic.CollectionDebuggerView'"
Never$$anonymous$$d, found the answer here: http://stackoverflow.com/questions/14329222/unity-weird-debugging
Yeah, neither of the solutions work for me. It underlines the "=" and "(" in red and give the error "Invalid token '=' in class, struct, or interface member declaration" for each
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Collections don't work! 1 Answer
DontDestroyOnLoad make errors 0 Answers
How to "get" an item from an ArrayList? 0 Answers
.dll files will not be loaded in latest unity version 2 Answers