MCQOPTIONS
Saved Bookmarks
| 1. |
The correct way to implement the property for which property reports the error invalid index if user attempts to cross bounds of the array for a student class with 5 intger arrays. a) class student { int []scores = new int[5] {23, 42, 54, 11, 65}; public int this[int index] { get { if (index < 5) return scores[index]; else { Console.WriteLine("invalid index"); return 0; } } set { if (index < 5) scores[index] = value; else Console.WriteLine("invalid index"); } } } b) class student { int []scores = new int[5] {23, 42, 54, 11, 65}; public int this[int index] { get { if (index < 5) return scores[index]; } } } c) class student { int []scores = new int[5]{23, 42, 54, 11, 65}; public int this[int index] { set { if (index < 5) return scores[index]; else { Console.WriteLine("invalid index"); return 0; } } } } |
| A. | A |
| B. | B |
| C. | C |
| D. | None of the mentioned |
| Answer» B. B | |