adplus-dvertising
frame-decoration

Question

Choose the output for the given set of 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();
    }
}

a.

Compile time error

b.

Run time error

c.

123, abc, xyz

d.

0

Answer: (b).Run time error

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Choose the output for the given set of code?

Similar Questions

Discover Related MCQs

Q. Choose the wrong statement about the properties used in C#.NET?

Q. Choose the statements which makes use of essential properties rather than making data member public in C#.NET?

Q. Where the properties can be declared?

Q. Select the modifiers which can be used with the properties?

Q. Choose the correct statements about write-only properties in C#.NET?

Q. Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the statement b.sum = 10 to fail.Which of the follwing is the correct

Q. Consider a class maths and we had a property called as sum.b which is the reference to a maths object and we want the statement Console.WriteLine(b.sum)to fail.Which among the following is the correct solution to ensure this functionality?

Q. Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the code below to work.Which is the correct solution to ensure this functionality?

b.maths = 10;
Console.WriteLine(b.maths);

Q. If math class had add property with get and set accessors, then which of the following statements will work correctly?

Q. If the math class had add property with get accessors then which of the following statements will work correctly?

Q. Select the correct statement about properties of read and write in C#.NET?

Q. Which among the following is NOT an exception?

Q. Which among the following is considered as .NET Exception class?

Q. Which of the following is the object oriented way to handle run time errors?

Q. Select the statements which describe the correct usage of exception handling over conventional error handling approaches?

Q. Select the correct statement about an Exception?

Q. Which of these keywords is not a part of exception handling?

Q. Which of these keywords must be used to monitor exceptions?

Q. Which of these keywords is used to manually throw an exception?

Q. Which of the following is the wrong statement about exception handling in C#.NET?