0
0
C Sharp (C#)programming~15 mins

Single-dimensional array declaration in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Single-dimensional array declaration
📖 Scenario: You are creating a simple program to store the names of fruits in a list. This list will help you keep track of fruits you want to buy from the market.
🎯 Goal: Build a program that declares a single-dimensional array of fruits, sets a size for it, fills it with fruit names, and then prints all the fruit names.
📋 What You'll Learn
Declare a single-dimensional array of strings called fruits with size 4
Assign the fruit names "Apple", "Banana", "Cherry", and "Date" to the array elements
Use a for loop with variable i to iterate over the array
Print each fruit name inside the loop using Console.WriteLine
💡 Why This Matters
🌍 Real World
Arrays are used to store lists of items like names, prices, or scores in many programs.
💼 Career
Knowing how to declare and use arrays is a basic skill for software developers working with data collections.
Progress0 / 4 steps
1
Declare a single-dimensional array
Declare a single-dimensional array of strings called fruits with size 4.
C Sharp (C#)
Need a hint?

Use string[] fruits = new string[4]; to create an array that can hold 4 fruit names.

2
Assign fruit names to the array
Assign the fruit names "Apple", "Banana", "Cherry", and "Date" to the array elements fruits[0], fruits[1], fruits[2], and fruits[3] respectively.
C Sharp (C#)
Need a hint?

Assign each fruit name to the correct index in the array using fruits[index] = "FruitName";.

3
Use a for loop to iterate over the array
Use a for loop with variable i to iterate over the fruits array from index 0 to 3.
C Sharp (C#)
Need a hint?

Use for (int i = 0; i < fruits.Length; i++) to loop through all elements.

4
Print each fruit name
Inside the for loop, use Console.WriteLine(fruits[i]) to print each fruit name.
C Sharp (C#)
Need a hint?

Use Console.WriteLine(fruits[i]); inside the loop to print each fruit.