To access array elements in C# using index, you can use square brackets notation.
In this example,
numbers
with integer values.2
using indexing numbers[1]
.using System;
class Program
{
static void Main()
{
int[] numbers = {1, 2, 3, 4, 5};
Console.WriteLine(numbers[1]);
}
}
2
In this example,
fruits
with string values.using System;
class Program
{
static void Main()
{
string[] fruits = {"Apple", "Banana", "Orange"};
foreach (string fruit in fruits)
{
Console.WriteLine(fruit);
}
}
}
Apple Banana Orange
In this tutorial, we learned How to Access Array Elements using Index in C# language with well detailed examples.