My Report

C# Classes Test – 2


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. Select the wrong statement about 'ref' keyword in C#?

2. Which reference modifier is used to define reference variable?

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

   static void Main(string[] args)
   {
       int a = 5;
       fun1 (ref a);
       Console.WriteLine(a);
       Console.ReadLine();
    }
    static void fun1(ref int a)
    {
        a = a * a;
    }
   

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

    
    static void Main(string[] args)
    {
       int X = 6,Y = 2;
       X  *= X / Y;
       Console.WriteLine(X);
       Console.ReadLine();
    }
   

5. What will be the output of the following C# expression?

 int  a+= (float) b/= (long)c.

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

  static void Main(string[] args)
  {
      int a = 10 , b = 20;
      Console.WriteLine("Result before swap is: "+ a +" "+b);
      swap(ref a, ref b);
      Console.ReadLine();
  }
  static void swap(ref int i, ref int j)
  {
      int t;
      t = i;
      i = j;
      j = t;
      Console.WriteLine("Result after swap is:"+ i +" "+j);
  }
 

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

 static void Main(string[] args)
 {
     int []a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
     func(ref a);
     Console.ReadLine();
 }
 static void func(ref int[] x)
 {
     Console.WriteLine(" numbers are:");
     for (int i = 0; i < x.Length; i++)
     {
         if (x[i] % 2 == 0)
         {
             x[i] = x[i] + 1;
             Console.WriteLine(x[i]);
         }
     }
 }

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

 static void Main(string[] args)
 {
     int[] arr = new int[] {1, 2, 3, 4, 5};
     fun1(ref arr);
     Console.ReadLine();
  }
 static void fun1(ref int[] array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = array[i] + 5;
         Console.WriteLine(array[i] + " ");
     }
 }

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

 
    static void Main(string[] args)
    {
        int x = 4 ,b = 2;
        x -= b/= x * b;
        Console.WriteLine(x + " " + b);
        Console.ReadLine();
    }
 

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

        
   static void Main(string[] args)
   {
       int x = 8;
       int b = 16;
       int C = 64;
       x /= b /= C;
       Console.WriteLine(x + " " + b+ " " +C);
       Console.ReadLine();
   }
  

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

       
   static void Main(string[] args)
   {
       int x = 8;
       int b = 16;
       int C = 64;
       x /= b /= C /= x;
       Console.WriteLine(x + " " + b+ " " +C);
       Console.ReadLine();
   }
  

12. Select correct differences between '=' and '==' in C#.

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

  static void Main(string[] args)
  {
      int X = 0;
      if (Convert.ToBoolean(X = 0))
      Console.WriteLine("It is zero");
      else 
      Console.WriteLine("It is not zero");
      Console.ReadLine();
  }
 

 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

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.