What Will Be The Output Of The Following C Codep Pre Langcsharp #481
What will be the output of the following C# code?</p> <pre><code class="language-csharp" line="1"> 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 Program { public static void Main(string[] args) { student s = new student(); Console.WriteLine(s[4] + 8); Console.ReadLine(); } } </code></pre>
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.