int[] arr=new int[10]{1,21,32,43,54,65,76,87,98,10};
foreach(var i in arr)
{
Console.WriteLine("Elements [{0}]:{1}",arr[i],i);
}
I want the output like
element[0]: 1
element[1]: 21
...
element[9]: 10
by using foreach
only, but I am getting this error:
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at Exercise1.Main () <0x41e47d70 + 0x0008c> in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.IndexOutOfRangeException: Index was outside the bounds of the array. at Exercise1.Main () <0x41e47d70 + 0x0008c> in :0