42

I'm having an error

The type or namespace name `List' could not be found. Are you missing a using directive or an assembly reference?

Sample code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class city1 : MonoBehaviour 
{  
   public static List<string> items = new List ();
   public static List<double> itemsprice = new List();
   public static List<double> qu = new List();
}

I'm using mono if it matters.

1
  • 1
    Try new List<string>(); instead of new List();. (and ...<double>, and so on). Commented Jul 30, 2015 at 21:03

3 Answers 3

26

The issue comes from your instantiation of new List(). These also need the generic component:

public static List<string> items = new List<string>();
public static List<double> itemsprice = new List<double>();
public static List<double> qu = new List<double>();

That is, there is no type List but there is a generic type List<T>.

More information and examples of instantiating the generic List<T> can be found in the MSDN documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

In my case I had to add using System.Collections.Generic;
2

Try this:

public static List<string[]> items = new List<string>();

Add brackets after string

Comments

1

List is a generic type in Unity. You should provide the item type while instantiating a List in Unity.

List<type> list = new List<type>();

Ex:

List<string> list = new List<string>();

Change your list declaration as below,

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class city1 : MonoBehaviour 
{  
   public static List<string> items = new List<string>();
   public static List<double> itemsprice = new List<double>();
   public static List<double> qu = new List<double>();
}

For more: https://learn.unity.com/tutorial/lists-and-dictionaries#

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.