Quantcast
Channel: Best way to "push" into C# array - Stack Overflow
Browsing latest articles
Browse All 13 View Live

Answer by Mondonno for Best way to "push" into C# array

There is another way to do this, which is fitting perfectly for extension class.public static void Push<T>(ref T[] table, object value){ Array.Resize(ref table, table.Length + 1);...

View Article



Answer by Flydog57 for Best way to "push" into C# array

Your question is a little off the mark. In particular, you say "that the element needs to be added into the first empty slot in an array, lie (sic) a Java push function would do."Java's Array does not...

View Article

Answer by Joshua M. Moore for Best way to "push" into C# array

I don't understand what you are doing with the for loop. You are merely iterating over every element and assigning to the first element you encounter. If you're trying to push to a list go with the...

View Article

Answer by Water Cooler v2 for Best way to "push" into C# array

C# is a little different in this respect with JavaScript. Because of the strict checks, you define the size of the array and you are supposed to know everything about the array such as its bounds,...

View Article

Answer by Michał Turczyn for Best way to "push" into C# array

As said before, List provides functionality to add elements in a clean way, to do the same with arrays, you have to resize them to accomodate extra elements, see code below:int[] arr = new...

View Article


Answer by Barr J for Best way to "push" into C# array

There are couple of ways this can be done. First, is converting to list and then to array again:List<int> tmpList = intArry.ToList();tmpList.Add(anyInt);intArry = tmpList.ToArray();Now this is...

View Article

Answer by UnbreakableMystic for Best way to "push" into C# array

I don't think there is another way other than assigning value to that particular index of that array.

View Article

Answer by Joshua M. Moore for Best way to "push" into C# array

Check out this documentation page: https://msdn.microsoft.com/en-us/library/ms132397(v=vs.110).aspxThe Add function is the first one under Methods.

View Article


Answer by Kamalesh Giri for Best way to "push" into C# array

This is acceptable as assigning to an array. But if you are asking for pushing, I am pretty sure its not possible in array. Rather it can be achieved by using Stack, Queue or any other data...

View Article


Answer by aloisdg for Best way to "push" into C# array

The is no array.push(newValue) in C#. You don't push to an Array in C#. What we use for this is a List<T>. What you may want to consider (for teaching purpose only) is the ArrayList (no generic...

View Article

Answer by jmcilhinney for Best way to "push" into C# array

array.push is like List<T>.Add. .NET arrays are fixed-size so you can't actually add a new element. All you can do is create a new array that is one element larger than the original and then set...

View Article

Answer by Anant Dabhi for Best way to "push" into C# array

As per comment "That is not pushing to an array. It is merely assigning to it"If you looking for the best practice to assign value to array then its only way that you can assign value.Array[index]=...

View Article

Best way to "push" into C# array

Good day allSo I know that this is a fairly widely discussed issue, but I can't seem to find a definitive answer. I know that you can do what I am asking for using a List, but that won't solve my...

View Article

Browsing latest articles
Browse All 13 View Live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>