Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
8
Question by DayyanSisson · Jul 13, 2012 at 10:46 PM · errorlistassemblyarraylist

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>();
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
32
Best Answer

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;

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OpenCoffee · Apr 18, 2013 at 11:04 AM 0
Share

Thank you for this great explanation :)

avatar image AItuarte · Jun 25, 2013 at 09:18 AM 0
Share

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

avatar image Nokes15 · Nov 25, 2013 at 04:55 AM 0
Share

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

avatar image whydoidoit Nokes15 · Nov 25, 2013 at 04:58 AM 0
Share

This is a comment and not an answer

avatar image
6

Answer by nivabeath · Mar 25, 2014 at 07:01 AM

 List<int> iList = new List<int>();
 iList.Add(2);
 iList.Add(3);
 iList.Add(5);

C# List examples ........ C# List

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges