What are the different ways to create an array in C#?
In C#, there are several ways to create an array:
- Initializing with arrays:
int[] numbers = {1, 2, 3, 4, 5};
- recent
int[] numbers = new int[5];
- Create an array instance
Array numbers = Array.CreateInstance(typeof(int), 5);
- Creating an array using the CreateInstance method.
int[] numbers = (int[])Array.CreateInstance(typeof(int), 5);