Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
3
Question by Freich · Jun 08, 2011 at 01:02 PM · arrayvaluearraylistcontent

Print arraylist values to console

With the help of info here I created a random unique number generator in an arraylist.

I want to print the arraylist content to my console but I only get this message: System.Collections.ArrayList

If I use .Count or .IndexOf it works. I can't find a solution anywhere on the internet. And Unity doesn't support arraylist in their documentation at all.

Thanks!

My code:

 var totalHumans:int = 8;
 var aHuman = ArrayList();
 
 function Start ()
 {
     while (aHuman.Count < totalHumans)
     {
         var human = Random.Range(0, 17);
         if (!aHuman.Contains(human))
         aHuman.Add(human);
         
     }
     Debug.Log(aHuman);
 }
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

4 Replies

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

Answer by Molix · Jun 08, 2011 at 01:48 PM

You can iterate over the list with something like:

 for( var human in aHuman )
 {
   Debug.Log( human );
 }
Comment
Add comment · Show 2 · 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 Freich · Jun 08, 2011 at 02:07 PM 0
Share

I'll try, thanks :)

avatar image Freich · Jun 09, 2011 at 09:37 AM 1
Share

It works, thank you.

avatar image
8

Answer by jana-jarecki · Jan 17, 2017 at 01:29 PM

In case anyone is still following up, here is what I use to get a one-line array output

 Debug.Log("Human = " +String.Join("",
             new List<int>(aHuman)
             .ConvertAll(i => i.ToString())
             .ToArray()));
Comment
Add comment · Show 3 · 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 gabearts · Aug 09, 2017 at 05:51 AM 0
Share

Worked Beautifully, thank you!

avatar image takibacsi · Sep 07, 2018 at 03:41 PM 0
Share

This is a very nice implementation, you can also concat several strings into one in the ConvertAll section. I use it to log child-parent name pairs.

avatar image diwang · Oct 13, 2019 at 05:15 AM 0
Share

For efficiency , ToArray() is not needed because unity already treat List<> similar to the way they treat array , so without ToArray() it still work and give better performance .

avatar image
0

Answer by Pflegeleichtt · Jun 08, 2011 at 01:48 PM

I think your're looking for an Array().

Comment
Add comment · Show 1 · 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 Freich · Jun 08, 2011 at 01:58 PM 1
Share

No, because I have to use .Contains. Which is only supported by ArrayList();

avatar image
0

Answer by iggy · Jun 08, 2011 at 01:51 PM

here are all the methods for ArrayList.

http://msdn.microsoft.com/en-us/library/system.collections.arraylist_methods(v=VS.85).aspx

i don't think there is one you seek.

why don't you add in your WHILE loop something like this:

Debug.Log("human"+aHuman.Count+"="+human);
Comment
Add comment · Show 2 · 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 Freich · Jun 08, 2011 at 02:06 PM 0
Share

Yes I read a lot on the pages there. Here the example staits: "The following code example shows how to create and initialize an ArrayList and how to print out its values". http://msdn.microsoft.com/en-us/library/7x4b0a97%28v=VS.80%29.aspx It's JavaScript, so I suppose it's possible? Bit difficult for me to understand.

Anyway thanks, I'll try what you said :)

avatar image iggy · Jun 08, 2011 at 11:14 PM 0
Share

yea just be careful when copy-pasting from $$anonymous$$SDN.

There is no "Console.Write" in Unity but use something similar like "Debug.Log()", etc...

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

8 People are following this question.

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

Related Questions

Assigning value stored in an array with get{} using cSharp 1 Answer

How to display data from array,arraylist while clicking the button? 1 Answer

Collections don't work! 1 Answer

Storing Level Data in Array of Array (grid-based game) 1 Answer

How to let multiple values contribute two one value constantly 1 Answer


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