Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,968 questions

51,910 answers

573 users

How to resize an array in C#

5 Answers

0 votes
using System;

public class ResizeArray
{
    public static void Main(string[] args)
    {
        int[] numbers = { 5, 3, 7, 2, 9 };
 
        Array.Resize(ref numbers, 3);
 
        for (int i = 0; i < numbers.Length; i++) {
            Console.Write(numbers[i] + ", ");
        }
    }
}



/*
run:

5, 3, 7, 

*/


answered Mar 4, 2015 by avibootz
edited Oct 13, 2025 by avibootz
0 votes
using System;

public class ResizeArray
{
    public static void Main(string[] args)
    {
        int[] numbers = { 5, 3, 7, 2, 9 };
 
        Array.Resize(ref numbers, 10);
 
        for (int i = 0; i < numbers.Length; i++) {
            Console.Write(numbers[i] + ", ");
        }
    }
}



/*
run:

5, 3, 7, 2, 9, 0, 0, 0, 0, 0, 

*/


answered Mar 4, 2015 by avibootz
edited Oct 13, 2025 by avibootz
0 votes
using System;

public class ResizeArray
{
    public static void Main(string[] args)
    {
        char[] array = new char[6] { 'c', 's', 'h', 'a', 'r', 'p' };
 
        Array.Resize(ref array, 3);
 
        for (int i = 0; i < array.Length; i++) {
            Console.Write(array[i] + ", ");
        }
    }
}



/*
run:

c, s, h, 

*/


answered Mar 4, 2015 by avibootz
edited Oct 13, 2025 by avibootz
0 votes
using System;

public class ResizeArray
{
    public static void Main(string[] args)
    {
        char[] array = new char[6] { 'c', 's', 'h', 'a', 'r', 'p' };
 
        Array.Resize(ref array, 10);
 
        for (int i = 0; i < array.Length; i++) {
            Console.Write(array[i] + ", ");
        }
    }
}



/*
run:

c, s, h, a, r, p, , , , , 

*/


answered Mar 4, 2015 by avibootz
edited Oct 13, 2025 by avibootz
0 votes
using System;

public class ResizeArray
{
    public static void Main(string[] args)
    {
        String[] arr = {"c#", "programming"};
 
        Array.Resize(ref arr, arr.Length + 2);
 
        arr[2] = "is";
        arr[3] = "fun";

        Array.ForEach(arr, x => Console.Write(x + ", "));
    }
}



/*
run:

c#, programming, is, fun, 

*/

 



answered Oct 13, 2025 by avibootz
...