C# Array Empty() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In C#, Array.Empty<T>() returns an empty array of type T[] with length 0. The runtime reuses one shared instance per type, so repeated calls do not allocate a new array every time.

Use it when an API needs an array argument and you have nothing to pass—cleaner and cheaper than new T[0] in hot paths.

This is a static member of System.Array. You call it with the class name, such as Array.Empty(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.

Syntax

Call the generic static method and store the result as T[].

C#
int[] none = Array.Empty<int>();
string[] names = Array.Empty<string>();
CallWhat it does
Array.Empty<int>()Returns a shared empty int array (Length 0).
Array.Empty<string>()Returns a shared empty string array.

Do not write into the empty array. There are no slots. Treat it as read-only length zero.

Library declarations
C#
public static T[] Empty<T>();

Parameters

ParameterDescription
TType argument. The element type of the empty array.

Return Value

Return ValueDescription
T[]An empty array of length 0. The same instance may be returned for every call of that T.

C# Examples

Example 1 — Get an Empty Int Array

Print length and show that there are no elements to loop.

C#
using System;

class Program {
    static void Main() {
        int[] none = Array.Empty<int>();

        Console.WriteLine("Length: " + none.Length);
        Console.WriteLine("Elements: [" + string.Join(", ", none) + "]");
    }
}

How It Works

  1. Generic call. Array.Empty<int>() asks for an empty int array.
  2. Length zero. There are no indexes to read.
  3. Join stays safe. string.Join on an empty sequence prints nothing between brackets.
  4. No allocation churn. Later calls for int can reuse the same instance.

Example 2 — Same Reference for Empty<T>

Two calls return the identical shared array object.

C#
using System;

class Program {
    static void Main() {
        string[] a = Array.Empty<string>();
        string[] b = Array.Empty<string>();

        Console.WriteLine(object.ReferenceEquals(a, b));
        Console.WriteLine(a.Length);
    }
}

How It Works

  1. ReferenceEquals. True means a and b point to one object.
  2. Per-type cache. Empty string arrays share one instance; empty int arrays share another.
  3. Do not mutate. Changing a “private” empty array would surprise every other caller.
  4. API default. Returning Array.Empty<T>() from a method avoids null and avoids new T[0].

Example 3 — Return Empty Instead of Null

A helper returns an empty array when there is no data—callers can foreach safely.

C#
using System;

class Program {
    static string[] GetTags(bool hasTags) {
        if (!hasTags) {
            return Array.Empty<string>();
        }
        return new string[] { "csharp", "array" };
    }

    static void Main() {
        string[] tags = GetTags(false);
        Console.WriteLine("Count: " + tags.Length);
        foreach (string t in tags) {
            Console.WriteLine(t);
        }
        Console.WriteLine("Done");
    }
}

How It Works

  1. No null. Callers never need if (tags == null) before looping.
  2. foreach is empty. The loop body never runs when Length is 0.
  3. Clear contract. Empty means “zero items,” which is clearer than null for many APIs.
  4. Cheap default. The shared empty array avoids a fresh allocation on every miss.

Frequently Asked Questions

A T[] with Length 0. The runtime may reuse one shared instance per T.
Yes for defaults and hot paths. Empty avoids repeated allocations and documents “no elements” clearly.
No useful slots exist. Do not treat the shared instance as a private buffer you can fill.
Usually no. Calls for the same T often return the same cached array object.
Prefer Empty (or an empty enumerable) so callers can foreach without null checks.

Next: Exists()

Return true if any element matches a predicate with System.Array.

Exists() tutorial →

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.

7 people found this page helpful