In C#, arrays can be initialized in several ways depending on the requirements of the program. Here are a few examples of initializing arrays in C#:
main.cs28 chars2 lines
This example initializes an integer array of size 5 with default values (0 in this case).
main.cs43 chars2 lines
This example initializes an integer array with values 1 to 5.
main.cs33 chars2 lines
This example is a shorter version of the previous example, but can only be used for array initialization.
main.cs120 chars3 lines
This initializes a boolean array with default values of false and a string array with default values of null.
main.cs49 chars2 lines
This initializes an integer array of size 5 with even numbers using an initialization expression.
These are just a few examples of how arrays can be initialized in C#. An array can also be initialized using other data types, such as strings, characters or objects.
gistlibby LogSnag