Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ioshi35 · Dec 07, 2016 at 07:28 AM · arraylist

Question about array

Hi guys

How to add and remove elements in array ? its kinda hard I wanna know the basic one.

Arr = new string[] {"love","hate","girl","head","to","me"};

here's my array

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
0

Answer by phxvyper · Dec 07, 2016 at 07:47 AM

in C# you cannot mutate an array like this. If you want a dynamic array I suggest looking at List

 var someList = new List<string>(new[] { "love","hate","girl","head","to","me" });
 
 // the list is now { "love","hate","girl","head","to","me","another" }
 someList.Add("another");
 
 // the list is now { "love","girl","head","to","me","another" }
 someList.RemoveAt(1);

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
avatar image
0

Answer by lspence812 · Dec 07, 2016 at 07:19 PM

You can also use an ArrayList if all elements will be of the same type (i.e. string).

 ArrayList arr = new ArrayList();
 arr.AddRange(new string[] { "love", "hate", "girl", "head", "to", "me" });
 
 // print the contents of the ArrayList
 names;
 
  // adding another element to the ArrayList
 names.Add("boy");
 
 // removing an element from the ArrayList
 names.Remove("head");
 

Both ArrayList and Generic Lists are collections; however, it is better to use a Generic List as it performs better and can contain mixed types.

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 ioshi35 · Dec 08, 2016 at 06:39 AM 0
Share

Cool .. if I have

arr.AddRange(new string[] { "love", "hate", "girl", "head", "to", "me" }); ArrayList arr = new ArrayList();

and I have this thing Arrs= new string[] {"happy","damn","boy","attack","be","cool"};

then how can I add data from Arrs to my arraList arr?

For example my arr is empty. Then I want to fetch some data from Arrs. Ill get 4 elements from it randomly .. is it possible ?

avatar image lspence812 · Dec 08, 2016 at 01:32 PM 0
Share

You could add a value from your Array to the ArrayList by providing the index of your Array value.

arr.Add(Arrs[3]);

The above would add "attack" to the ArrayList giving you the values: "love", "hate", "girl", "head", "to", "me", "attack"

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

87 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Array (List) with multiple variable types? 2 Answers

Array Inspector 0 Answers

Get all Children of an Object with a certain component 0 Answers

How to perform this Word Game 0 Answers

Keeping track of dynamic positions of items in a grid using List/Array? 0 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