What Will Be The Output Of The Following Code Snippet:
public class Quiz
{
public static void Main(string[] args)
{
int[] i = new int[0];
Console.WriteLine(i[0]);
}
}
a) 0
b) Nothing is printed as array is empty
c) Compile time error
d) IndexOutOfRangeException
e) 1
5
Answers
What Will Be The Output Of The Following Code Snippet:
public class Quiz
{
public static void Main(string[] args)
{
int[] i = new int[0];
Console.WriteLine(i[0]);
}
}
a) 0
b) Nothing is printed as array is empty
c) Compile time error
d) IndexOutOfRangeException
e) 1
The answer is d) IndexOutofRangeException, the number of elements in the array is 0 and the program is trying to access the first element in the array.