What will be the output of the following C# code?
class list
{
ArrayList array = new ArrayList();
public object this[int index]
{
get
{
if (index < 0 || index >= array.Count)
{
return null;
}
else
{
return (array[index]);
}
}
set
{
array[index] = value;
}
}
public int Count
{
get;
set;
}
}
class Program
{
static void Main(string[] args)
{
list list1 = new list();
list1[0] = "123";
list1[1] = " abc ";
list1[2] = "xyz";
for (int i = 0; i<=list1.Count; i++)
Console.WriteLine(list1[i]);
Console.ReadLine();
}
}
class list
{
ArrayList array = new ArrayList();
public object this[int index]
{
get
{
if (index < 0 || index >= array.Count)
{
return null;
}
else
{
return (array[index]);
}
}
set
{
array[index] = value;
}
}
public int Count
{
get;
set;
}
}
class Program
{
static void Main(string[] args)
{
list list1 = new list();
list1[0] = "123";
list1[1] = " abc ";
list1[2] = "xyz";
for (int i = 0; i<=list1.Count; i++)
Console.WriteLine(list1[i]);
Console.ReadLine();
}
}A. Compile time error
B. Run time error
C. 123, abc, xyz
D. 0
Answer: Option B
Related Questions on Exception Handling in C Sharp
What is the purpose of exception handling in C#?
A. To enhance program performance
B. To avoid writing error messages
C. To gracefully handle runtime errors
D. To simplify debugging
What is the default exception handler in C# called?
A. Standard Exception Handler
B. Unhandled Exception Handler
C. Global Exception Handler
D. None of the above
A. throw
B. catch
C. finally
D. try

Join The Discussion