Question: If you try to access an array using an index outside of its bounds, C# returns an array out - of - bounds exception. Aside

If you try to access an array using an index outside of its bounds, C# returns an "array out-of-bounds exception". Aside from the fact that you cannot use an index that is out-of-bounds, why do you think this is a problem? In other words, why do you think C# does not let you access something out-of-bounds?
{
internal class Program
{
static void Main(string[] args)
{
string[] names = new string[10];
for (int i =0; i <10; ++i)
{
Console.Write("name: ");
string name = Convert.ToString(i);
Console.ReadLine();
Console.WriteLine(names);
}
Console.WriteLine($"You entered: {names}");
Console.WriteLine("
Press any key to continue...");
Console.ReadKey();
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!