My Report

C# Programming Practice Test 6


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which among the following is the correct form of applying an attribute?

2. Which of these keywords is not a part of exception handling?

3. 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();
     }
 }

4. Which of these keywords is used to manually throw an exception?

5. Choose the correct alternative that utilizes the indexed property such that a group named class has indexed property which stores or retrieves value to/from an array of 5 numbers?

6. The correct way to apply the custom attribute called Employer which receives two arguments - name of the employee and employeeid is?

7. What will be the output of the following C# code snippet?

 class Program
 {
     static void Main(string[] args)
     {
         int i;
         int v = 40;
         int[] x = new int[5];
         try
         {
             Console.WriteLine(" Enter the number: ");
             index = Convert.ToInt32(Console.ReadLine());
             x[index] = v;
         }
         catch(Exception e)
         {
             Console.WriteLine("Exception occurred");
         }
         Console.WriteLine("Program executed");
     }
 }

8. Select the correct statement about properties of read and write in C#.NET?

9. Which of the following is the object oriented way to handle run time errors?

10. Choose the keyword which declares the indexer?


 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.