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();
Call
What 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
Parameter
Description
None
Initialize() takes no parameters.
Return Value
Return Value
Description
void
Elements 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]);
}
}
Output
after new: 10,10
mutated: 99,99
init: 10,10
How It Works
Field initializer.Value = 10 runs for each element on creation.
Mutate. Both elements become 99.
Initialize(). Field initializers run again.
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));
}
}
Output
0, 0, 0
How It Works
Value types. int elements are reset to default 0.
Whole array. Initialize touches every element.
Readable alternative.Array.Clear(nums, 0, nums.Length) is clearer for many readers.
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));
}
}
Output
0,0,0
0,0,0
How It Works
Same zeros. For int[], both approaches reset values.
Clear is explicit. Beginners often recognize Clear faster.
Structs differ. Initialize shines when field initializers matter.
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.