Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

List and Dictionaries not recognized as a Type in C#

Discussion in 'Scripting' started by seshdroid, Apr 20, 2014.

  1. seshdroid

    seshdroid

    Joined:
    Apr 20, 2014
    Posts:
    1
    In spite of having imported the System.Collections.Generic class, in C#, I'm still unable to understand why I get error CS0103 the name List is not exist in the current context.
    I've searched almost everywhere I could but I can't get a solution. I am using the free version of unity 4.0.3 and I don't know if it is not possible to use Generic classes such as List and Dictionaries in it. I know that it lives in C# and not unity. I also don't know if mine is a local error or not.

    Now the code
    Code (csharp):
    1. List<string> myFavoriteColors = new List<string>();
    highlights as if the type List is not recognized.
    When I see the console, I see nothing there. at the same time, when I hit the play button of unity, It will run the code and no error is shown, However, there is no output as well!!!

    Please help!

    Many thanks in advance :)
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Can you post the whole script?
     
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Do you mean;

    Code (csharp):
    1.  
    2. using System.Collections.Generic;
    3.  
    right?

    Better post a longer example of your issue.
     
  4. gm2008

    gm2008

    Joined:
    Aug 8, 2014
    Posts:
    19
    I encountered the same problem. I found that the same type of variables in other files , like List<string>, worked well. It turned out that after retyping the line "using System.Collections.Generic;", it was resolved!

    This is really strange.
     
  5. josepvalls

    josepvalls

    Joined:
    Jul 17, 2013
    Posts:
    1
    How did you guys fix this?
     
  6. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Over a year ago? Even if they happened to be around, would they remember? Just make a new thread rather than necro'ing old ones IMO.

    Be sure you have "using System.Collections.Generic;" at the top of the script in the namespace references.

    If it's not recognizing it despite that namespace being included, most of the time it's caused from you having an error somewhere else in your code, usually completely unrelated, and THEN including a new namespace. It's not going to bother pulling in those references if it's already got a problem to deal with.

    Occasionally, it can also just be a weird error in the editor. Restarting it (or Unity, if necessary), will fix it in those cases.
     
  7. ephraimdov

    ephraimdov

    Joined:
    Sep 12, 2015
    Posts:
    2