capypad
0 day streak
csharp / beginner
Snippet

Working with Arrays

An array stores a fixed-size collection of elements of the same type. You access elements using an index, starting at 0.

snippet.csharp
csharp
1
2
3
string[] inventory = { "Sword", "Shield", "Potion" };
Console.WriteLine(inventory[0]);
Console.WriteLine(inventory.Length);
Breakdown
1
string[] inventory = { ... };
Creates an array of strings with three initial values.
2
inventory[0]
Accesses the first element in the array ("Sword").
3
inventory.Length
A property that returns the total number of items in the array.