C# Array Initialize() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In C#, Initialize is an instance method that re-initializes each element of a value-type array by running the value type’s default initialization logic again (field initializers / default constructor behavior).

For arrays of primitive ints it behaves like setting defaults. It is most meaningful for arrays of custom structs that have field initializers. Reference-type arrays are not the usual target.

This is an instance member of System.Array. You call it on an array variable with a dot, such as arr.Initialize(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.

Syntax

Call Initialize on the array instance with empty parentheses.

C#
points.Initialize();
CallWhat it does
points.Initialize()Re-initializes each value-type element in place.

For simple “set everything to 0” on int[], Array.Clear or Array.Fill is clearer for beginners.

Library declarations
C#
public void Initialize();

Parameters

ParameterDescription
NoneInitialize() takes no parameters.

Return Value

Return ValueDescription
voidElements are re-initialized in place.

C# Examples

Example 1 — Re-Initialize Struct Fields

After mutating structs, Initialize restores field initializer values.

C#
using System;

struct Counter {
    public int Value = 10;
    public override string ToString() => Value.ToString();
}

class Program {
    static void Main() {
        Counter[] items = new Counter[2];
        Console.WriteLine("after new: " + items[0] + "," + items[1]);

        items[0].Value = 99;
        items[1].Value = 99;
        Console.WriteLine("mutated:   " + items[0] + "," + items[1]);

        items.Initialize();
        Console.WriteLine("init:      " + items[0] + "," + items[1]);
    }
}

How It Works

  1. Field initializer. Value = 10 runs for each element on creation.
  2. Mutate. Both elements become 99.
  3. Initialize(). Field initializers run again.
  4. Back to 10. Both slots show the restored value.

Example 2 — Initialize on Ints

For ints, Initialize restores zeros—similar to Clear on the whole array.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 1, 2, 3 };
        nums.Initialize();
        Console.WriteLine(string.Join(", ", nums));
    }
}

How It Works

  1. Value types. int elements are reset to default 0.
  2. Whole array. Initialize touches every element.
  3. Readable alternative. Array.Clear(nums, 0, nums.Length) is clearer for many readers.
  4. Length same. Still three slots.

Example 3 — Compare With Array.Clear

Show Clear producing the same zeros on an int array.

C#
using System;

class Program {
    static void Main() {
        int[] a = { 4, 5, 6 };
        int[] b = { 4, 5, 6 };

        a.Initialize();
        Array.Clear(b, 0, b.Length);

        Console.WriteLine(string.Join(",", a));
        Console.WriteLine(string.Join(",", b));
    }
}

How It Works

  1. Same zeros. For int[], both approaches reset values.
  2. Clear is explicit. Beginners often recognize Clear faster.
  3. Structs differ. Initialize shines when field initializers matter.
  4. Pick for readers. Prefer the call your team finds obvious.

Frequently Asked Questions

It re-initializes value-type elements using their default initialization / field initializers.
Array.Clear or Array.Fill is usually clearer for wiping primitive arrays.
No.
It is intended for value-type elements. Use Clear/Fill for reference-type wipes.
Yes. Call it on the array: arr.Initialize().

Next: LastIndexOf()

Return the last index of a value, or -1 if it is missing with System.Array.

LastIndexOf() 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.

14 people found this page helpful