Mark As Completed Discussion

Arrays and Collections

In .NET, arrays and collections are used to store multiple values in a single variable. They provide a convenient way to work with groups of related data.

Arrays

An array is a fixed-size collection of elements of the same type. It allows you to store and access multiple values using a single variable. The elements in an array are accessed by their index, which starts at 0.

Here's an example of initializing and accessing elements in an array:

TEXT/X-CSHARP
1string[] names = { "Alice", "Bob", "Charlie", "Dave" };
2
3Console.WriteLine(names[0]); // Output: Alice
4Console.WriteLine(names[2]); // Output: Charlie
CSHARP
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment