C# Create an Empty Array
To create an empty array in C#, call Array.Empty<T>() method where T is the datatype of elements in the array.
Example
In the following example, we create an empty string array in arr. To confirm, we shall print the length of this empty array to console.
Program.cs
</>
Copy
using System;
namespace CSharpExamples {
class Program {
static void Main(string[] args) {
string[] arr = Array.Empty<string>();
Console.WriteLine("Length of Array : " + arr.Length);
}
}
}
Output
Length of Array : 0
Conclusion
In this C# Tutorial, we learned how to create an empty array, with examples.
