C# Arrays

Beginner
7 min read
Updated: Nov 2026
3 examples
Array

Definition and Usage

In C#, an array stores a fixed number of elements of the same type in one block of memory. You write int[] scores = { 90, 85, 70 }; or new int[5]. Indexes start at 0. The length is fixed for that array object—you cannot Add a sixth slot without allocating a new array.

The type System.Array is the base for all arrays. It offers helpers such as Sort(), Find(), IndexOf(), and Copy(). Many calls are static: Array.Sort(arr).

This page teaches what a C# array is. The Array Methods index lists every method guide in this series.

Need a growing collection?

Use List<T> when the count changes while the program runs. Convert with list.ToArray() when an API needs an array.

C# Syntax

Common ways to create and use arrays:

C#
int[] a = { 1, 2, 3, 4, 5 };   // five ints
int[] zeros = new int[5];      // five zeros
int n = a.Length;              // 5
int x = a[0];                  // first element
Array.Sort(a);                 // sort in place
int ix = Array.IndexOf(a, 3);  // index or -1

Array vs List<T>

The two are easy to mix up. Here is a quick comparison:

Featureint[]List<int>
Length / CountFixed after createCan grow and shrink
Add / RemoveNo (use Resize or new array)Yes
Indexinga[i]list[i]
HelpersArray.Sort, Array.Find, …Add, Find, LINQ, …
Best forFixed buffers, simple APIsChanging collections

C# Examples

Three short programs that show how arrays work with System.Array helpers.

Example 1 — Create, Length, Sort, and IndexOf

A first program that uses common Array helpers.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 40, 10, 30, 20 };

        Console.WriteLine("Length: " + nums.Length);

        Array.Sort(nums);
        Console.WriteLine("After Sort: " + string.Join(", ", nums));

        int ix = Array.IndexOf(nums, 30);
        Console.WriteLine("Index of 30: " + ix);
    }
}

How It Works

  1. Fixed length. nums holds four ints; Length reports 4 and never changes for this object.
  2. Sort in place. Array.Sort(nums) reorders the same array to ascending order.
  3. Find an index. IndexOf returns 2 for value 30, or -1 when missing.

Example 2 — Find the First Match with a Predicate

A predicate is a tiny yes/no test. Array.Find returns the first element that passes.

C#
using System;

class Program {
    static void Main() {
        string[] names = { "Ann", "Bob", "Carla", "Dan" };

        string hit = Array.Find(names, n => n.Length > 3);

        Console.WriteLine(hit ?? "(none)");
    }
}

How It Works

  1. Lambda test. n => n.Length > 3 is true only for longer names.
  2. First win. Find stops at "Carla" and does not keep scanning.
  3. Missing value. If nothing matches, reference types return null (the default).

Example 3 — Copy Elements and Resize with ref

Copy fills another array. Resize replaces your variable with a new array of a different length.

C#
using System;

class Program {
    static void Main() {
        int[] src = { 1, 2, 3 };
        int[] dest = new int[5];

        Array.Copy(src, dest, src.Length);
        Console.WriteLine("dest: " + string.Join(", ", dest));

        Array.Resize(ref src, 5);
        Console.WriteLine("src Length: " + src.Length);
        Console.WriteLine("src: " + string.Join(", ", src));
    }
}

How It Works

  1. Copy count. Three values move into dest; the extra slots stay 0.
  2. New array. Resize allocates length 5 and copies old data into src.
  3. Need ref. Without ref, the caller variable would still point at the old shorter array.

Next: C# Array Methods Index

After you know what an array is, open the method index for a full tutorial on each System.Array API.

Start withWhy
Sort()Order elements in place
IndexOf()Find a value by equality
Find()Find by a custom condition
Copy()Copy elements to another array

Full list: C# Array Methods index (/c-sharp/array/method).

Frequently Asked Questions

An array is a fixed-length collection of elements of one type, such as int[] or string[]. Indexes start at 0. After you create it, Length does not change for that object.
Arrays have a fixed length. List<T> can grow with Add and shrink with Remove. Prefer List when the count changes often; prefer arrays for fixed buffers and simple APIs.
Static methods use Array.Name(...), for example Array.Sort(arr) and Array.Find(arr, predicate). Instance methods use a dot on the array, for example arr.Clone() and arr.GetLength(0).
Yes. Sort first (or build the array already ordered). Searching an unsorted array gives undefined results.
Open the C# Array Methods index. It lists Sort, Find, IndexOf, Copy, Resize, GetLength, and the rest, each with examples and FAQs.

Browse every array method

Open the methods index for categorized guides with examples and FAQs.

Array Methods Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful