# accessing array using \[\] method

**URL:** <https://discussions.unity.com/t/accessing-array-using-method/395034>\
**Category:** Scripting\
**Tags:** Scripting\
**Created:** [July 17, 2009, 8:37pm UTC](https://discussions.unity.com/t/accessing-array-using-method/395034 "2009-07-17T20:37:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon\_81595149](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@anon\_81595149](https://discussions.unity.com/u/anon_81595149)\
**Post date:** [July 17, 2009, 8:37pm UTC](https://discussions.unity.com/t/accessing-array-using-method/395034/1 "2009-07-17T20:37:34Z")

</div>

If I create an array using

var arr = new Array (“Hello”, “World”);

I can easily remove an element using

arr.RemoveAt(1);

Now, if I create the array this way:

var objs : GameObject[&nbsp;];

and add the elements in the interface, how do I get acces to them?

objs.RemoveAt(1); doesn’t work. It’s probably very stupid. I searched the doc and the forum but I couldn’t find an example.

EDIT: I need to know how to make RemoveAt working with the second method of arrays.

---

<div class="post-metadata">

**Author:** ![GargerathSunman](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gargerathsunman/32/185234_2.png) [@GargerathSunman](https://discussions.unity.com/u/GargerathSunman)\
**Post date:** [July 17, 2009, 9:50pm UTC](https://discussions.unity.com/t/accessing-array-using-method/395034/2 "2009-07-17T21:50:06Z")

</div>

Well, since your array is of gameObjects, just do this:

var holder : GameObject = arrayName[0];

That’ll get you the position at the first spot in the array. 1 is second spot, 2 is third spot, etc…

So, to summarize, any variable of type GameObject can just = arrayName[integer];

---

<div class="post-metadata">

**Author:** ![anon\_81595149](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@anon\_81595149](https://discussions.unity.com/u/anon_81595149)\
**Post date:** [July 17, 2009, 10:05pm UTC](https://discussions.unity.com/t/accessing-array-using-method/395034/3 "2009-07-17T22:05:01Z")

</div>

Actually I didn’t explain de problem properly.

What I need is how do you use the removeAt when using the var objs : GameObject[&nbsp;] method instead of the var arr = new Array (“Hello”, “World”)

---

<div class="post-metadata">

**Author:** ![anon\_85768832](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@anon\_85768832](https://discussions.unity.com/u/anon_85768832)\
**Post date:** [July 17, 2009, 10:31pm UTC](https://discussions.unity.com/t/accessing-array-using-method/395034/4 "2009-07-17T22:31:05Z")

</div>

> [@""](#):
>
> What I need is how do you use the removeAt when using the var objs : GameObject[&nbsp;] method instead of the var arr = new Array (“Hello”, “World”)

Well, you don’t as per the [Array](http://unity3d.com/support/documentation/ScriptReference/Array.html) entry in the scripting reference which states:

_Builtin arrays (native .NET arrays), are extremely fast and efficient but they can not be resized._

If you need to remove an entry then you’ll have to convert the built-in array to a standard array, modify it by removing elements, then convert it back to a built-in array. Check the [Array](http://unity3d.com/support/documentation/ScriptReference/Array.html) page in the script reference as it shows you how to do that.

Rock on! 🙂

---

<div class="post-metadata">

**Author:** ![anon\_81595149](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@anon\_81595149](https://discussions.unity.com/u/anon_81595149)\
**Post date:** [July 17, 2009, 10:43pm UTC](https://discussions.unity.com/t/accessing-array-using-method/395034/5 "2009-07-17T22:43:30Z")

</div>

I read about that in the doc, I just didn’t know that the array in the interface was a .Net one.

Thanks!

-R

---

<div class="post-metadata">

**Author:** ![Adrian](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/adrian/32/93991_2.png) [@Adrian](https://discussions.unity.com/u/Adrian)\
**Post date:** [July 18, 2009, 6:20pm UTC](https://discussions.unity.com/t/accessing-array-using-method/395034/6 "2009-07-18T18:20:14Z")

</div>

The .Net array is documented here:

> **[Array Class (System)](https://learn.microsoft.com/en-us/dotnet/api/system.array?view=net-9.0&redirectedfrom=MSDN)**
>
> Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.

There is actually a Resize() method, though since the array is fixed-length, that will internally copy the array into a new resized one. If you only need to resize the array seldom, that’s not a big issue.

---

<div class="post-metadata">

**Author:** ![gamenut30111](https://avatars.discourse-cdn.com/v4/letter/g/9e8a1a/32.png) [@gamenut30111](https://discussions.unity.com/u/gamenut30111)\
**Post date:** [April 20, 2010, 12:13pm UTC](https://discussions.unity.com/t/accessing-array-using-method/395034/7 "2010-04-20T12:13:28Z")

</div>

They may have solved your problem, but i would also like to contribute 🙂

I am pretty sure you can also do this

```auto
var theoneuwanttoremove : GameObject
var waste : GameObject;

gos[0] = theoneuwanttoremove;
gos[0] = waste;

```
