Array example in C#

Mohammad Zubair 0
Logo

Here’s an example of how you can declare and use an array in C#:

using System;

class Program
{
static void Main()
{
// Declare and initialize an array of integers
int[] numbers = new int[5]; // Creating an array that can hold 5 integers

// Assign values to the array elements
numbers[0] = 10;
numbers[1] = 20;
numbers[2] = 30;
numbers[3] = 40;
numbers[4] = 50;

// Access and print array elements
Console.WriteLine("Array elements:");
for (int i = 0; i < numbers.Length; i++)
{
Console.WriteLine($"numbers[{i}] = {numbers[i]}");
}
}
}

Mohammad Zubair

I'm Mohammad Zubair, a passionate software engineer working in the dynamic world of IT. Currently, I'm proud to be a part of HawarIT, a thriving Dutch-Bangladeshi joint venture company, where I contribute my expertise and enthusiasm to the field of software engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *