- Home /
error CS0246: The type or namespace name `List' could not be found.
I'm trying to create a list within C# and I'm getting the error: Assets/Scripts/LevelHandler.cs(6,16): error CS0246: The type or namespace name `List' could not be found. Are you missing a using directive or an assembly reference?
Isn't this the setup for creating lists?
using UnityEngine;
using System.Collections.Generic; /*This should be used for LIST to work, right?*/
public class LevelHandler : MonoBehaviour {
public List items = new List();
}
Answer by Dave-Carlile · Feb 05, 2013 at 08:03 PM
System.Collections.Generic
is for generic list declarations, e.g. List{MyClass}
. Lists that don't use generics, as you're using, are in System.Collections
. I would highly recommend using generics with lists, since the old non-generics versions can cause garbage collection issues due to boxing and unboxing.
NOTE: replaced the less-than/greater-than with curly braces since they get stripped out.
so ins$$anonymous$$d of using what the OP had use something like this: public List items = new List<int>();
Your answer
Follow this Question
Related Questions
Need help with ArgumentOutOfRange Error 1 Answer
What does "The type or namespace name x could not be found" mean? 5 Answers
Multiple Cars not working 1 Answer
C# error - A namespace can only types and namespace declarations 2 Answers
Cannot convert float to int when only using floats (C#) 3 Answers