Multiple choice

What is the error in the following code? using System; class Employee { private string[]name = new string[10]; public static string this[int index] { get { return name[index]; } set { name[index] = value; } } } class Test { public static void Main() { Employee emp = new Employee(); emp[0] = Sachin; emp[1] = Rohit; emp[2] = Amit; Console.WriteLine(Emploees are:); for (int i = 0; i < 3;i++) { Console.WriteLine(emp[i]); } Console.ReadLine(); } }

  1. The private modifier can not be used before array declaration.

  2. It will throw an exception.

  3. The static modifier is invalid in the code.

  4. The 'this' keyword is invalid in the code.

  5. No error

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

We can not use static modifier in indexer declaration as static methods can not be used with a particular instance of the class and the indexer uses the instances of the class.