Introduction

Completed

C# arrays allow you to store sequences of values in a single data structure. In other words, imagine a single variable that can hold many values. Once you have a single variable that stores all the values, you can sort the values, reverse the order of the values, loop through each value and inspect it individually, and so on.

Suppose you work in the security department of a company that matches online sellers with commission-based advertisers. You've been asked to write C# code that will iterate through the Order IDs of incoming orders. You need to inspect each Order ID to identify orders that may be fraudulent. You'll need to implement arrays to accomplish this programming task.

In this module, you'll create and initialize arrays. You'll set and retrieve values from elements in an array accessing each element using its index. You'll create looping logic that allows you to work with each element in an array.

By the end of this module, you'll have worked with your first structure to hold multiple data values. Later, in other modules, you'll learn how to sort, filter, query, aggregate, and perform other operations on your data.

Important

This module includes coding activities that require Visual Studio Code. You'll need access to a development environment that has Visual Studio Code installed and configured for C# application development.

Learning objectives

In this module you will:

  • Create and initialize a new array.
  • Assign and retrieve the values of array elements.
  • Iterate through each element of an array using the foreach statement.

Prerequisites

  • Experience using Visual Studio Code to create and run C# console applications.
  • Experience printing messages to the console using Console.WriteLine().
  • Experience using string interpolation to combine literal strings with variable data.
  • Experience researching how to use methods from the .NET Class Library on learn.microsoft.com.