Learn C#: Arrays and Loops
Learn how to organize data and automate repetitive tasks with arrays and loops.
StartKey Concepts
Review core concepts you need to learn to master this subject
C# Arrays
Declaring Arrays
Declare and Initialize array
Array Element Access
C# Array Length
C# For Loops
C# For Each Loop
C# While Loop
C# Arrays
C# Arrays
// `numbers` array that stores integers
int[] numbers = { 3, 14, 59 };
// 'characters' array that stores strings
string[] characters = new string[] { "Huey", "Dewey", "Louie" };
In C#, an array is a structure representing a fixed length ordered collection of values or objects with the same type.
Arrays make it easier to organize and operate on large amounts of data. For example, rather than creating 100 integer variables, you can just create one array that stores all those integers!
Arrays
Lesson 1 of 2
- 1You want to write a program that keeps track of the heights of different plants in your garden. You could do this as a series of variables, but those would become difficult to work with really fast…
- 2In C#, arrays are a collection of values that all share the same data type. You could have an array of type string that contains a list of your favorite songs, or an array of type int that stores a…
- 3We often want to know how many items an array contains. We can do this with the .Length property. int[] plantHeights = { 3, 4, 6 }; // arrayLength will be 3 int arrayLength = plantHeights.Length…
- 4Arrays are useful for storing values, but they’re not very useful if they simply stay there — we also need a way to access them. Arrays order items so that they’re in a specific sequence, w…
- 5Once we create an array, the size of that array is fixed. However, it’s possible to change the values it contains. For example, we can initialize an array that has a length of three without speci…
- 6In C#, there are several built-in methods we can use with arrays. The full list can be found in the [Microsoft documentation of the Array class, under methods](https://docs.microsoft.com/en-us/dotn…
- 7In addition to Sort(), IndexOf(), and Find(), there are several other built-in methods for arrays. You can find them (and you probably guessed it) in the [Microsoft documentation](https://docs.micr…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory