Ad space (banner)
#๏ธโƒฃC# Lessons
Lesson 7 / 68

Working with Arrays

In this lesson you will learn the basics of arrays in C# so you can handle several pieces of data together. This is for anyone searching for "C# array how to use".

An array is like a shelf of numbered drawers. You can supply all of the initial values at once with { }.

The sample code builds an array with string[] fruits = { "apple", "orange", "grape" }, then combines a for loop with fruits.Length to print each item with its number. The length of an array is easy to read from the .Length property.

A common stumbling block for beginners is that accessing a position past the end of the array raises an error. C# is friendlier than C, where you had to track the element count yourself, but out-of-range access still needs care.

In real-world development, arrays turn up everywhere you need to handle several values of the same kind, such as a scoreboard in a game or a list of stock quantities.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C# directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)