ExamVeda
Login
Home
Exception Handling in C Sharp
?

What will be the output of the following C# code?
class student
{
    int []scores = new int[3] {13, 32, 24};
    public int this[int index]
    {
        get
        {
            if (index < 3)
            return scores[index];
            else
            {
                Console.WriteLine("invalid index");
                return 0;
            }
        }
        private  set
        {
            if (index < 3)
            scores[index] = value;
            else
            Console.WriteLine("invalid index");
        }
    }
}
class Program
{
    public static void Main(string[] args)
    {
        student s = new student();
        int[] scores1 = new int[3] {8, 19, 40};
        for (int i = 0; i < 3; i++)
        {
            if (scores1[i] > s[i])
            {
                Console.WriteLine(" scores1 had greater value :" + scores1[i]);
            }
            else
            {
                Console.WriteLine("scores had greater value :" + s[i]);
            }
        }
        Console.ReadLine();
    }
}

Answer & Solution
Correct Answer: Option D
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.