The Correct Way To Implement The Property For Which Property #482
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 integer arrays.
This multiple choice question (MCQ) is related to the book/course gs gs108 CSharp. It can also be found in gs gs108 Indexers and Exception Handling - Properties and its Applications - Quiz No.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 integer arrays.
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"); } } }
class student { int []scores = new int[5] {23, 42, 54, 11, 65}; public int this[int index] { get { if (index < 5) return scores[index]; } } }
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; } } } }
None of the mentioned