Quantcast
Channel: Best way to "push" into C# array - Stack Overflow
Viewing all articles
Browse latest Browse all 13

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

$
0
0

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 not recommended as you convert to list and back again to array. If you do not want to use a list, you can use the second way which is assigning values directly into the array:

int[] terms = new int[400];for (int runs = 0; runs < 400; runs++){    terms[runs] = value;}

This is the direct approach and if you do not want to tangle with lists and conversions, this is recommended for you.


Viewing all articles
Browse latest Browse all 13

Trending Articles



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