C# (C Sharp) MCQs with answers Page - 19

Here, you will find a collection of MCQ questions on C# (C Sharp). Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833.24K Points
Coach

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

Code:
int a,b;
  a = (b = 10) + 5;
  • (A) b = 10, a = 5
  • (B) b = 15, a = 5
  • (C) a = 15, b = 10
  • (D) a = 10, b = 10

A

Admin • 833.24K Points
Coach

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

Code:
static void Main(string[] args)
{
    String name = "Dr.Gupta";
    Console.WriteLine("Good Morning" + name);
}
  • (A) Dr.Gupta
  • (B) Good Morning
  • (C) Good Morning Dr.Gupta
  • (D) Good Morning name

A

Admin • 833.24K Points
Coach

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

Code:
static void Main(string[] args)
 {
     int a = 5;
     int b = 10;
     int c;
     Console.WriteLine(c = a-- - ++b);
     Console.WriteLine(b);
     Console.ReadLine();
 }
  • (A) -7, 10
  • (B) -5, 11
  • (C) -6, 11
  • (D) 15, 11

A

Admin • 833.24K Points
Coach

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

Code:
static void Main(string[] args)
 {
     const int a = 5;
     const int b = 6;
     for (int i = 1; i <= 5; i++)
     {
         a = a * i;
         b = b * i;
     }
     Console.WriteLine(a);
     Console.WriteLine(b);
     Console.ReadLine();
 }
  • (A) 600, 720
  • (B) Compile time error
  • (C) 25, 30
  • (D) 5, 6

A

Admin • 833.24K Points
Coach

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

Code:
static void Main(string[] args)
 {
     string Name = "He is playing in a ground.";
     char[] characters = Name.ToCharArray();
     StringBuilder sb = new StringBuilder();
     for (int i = Name.Length - 1; i >= 0; --i)
     {
         sb.Append(characters[i]);
     }
     Console.Write(sb.ToString());
     Console.ReadLine(); 
 }
  • (A) He is playing in a grou
  • (B) .ground a in playing is He
  • (C) .dnuorg a ni gniyalp si eH
  • (D) He playing a

A

Admin • 833.24K Points
Coach

Q. Choose the correct type of variable scope for the following C# defined variables.

Code:
class ABC
  {
      static int m;
      int n;
      void fun (int x , ref int y, out int z, int[] a)
      {
         int j = 10;
      }
  }
  • (A) m = static variable, n = local variable, x = output parameter, y = reference parameter, j = instance variable, z = output parameter, a[0] = array element
  • (B) m = static variable, n = instance variable, x = value parameter, y = reference parameter, j = local variable, z = output parameter , a[0] = array element
  • (C) m = static variable, n = instance variable, x = reference parameter, y = value parameter, j = local variable, z = output parameter, a[0] = array element
  • (D) m = local variable, n = instance variable, x = reference parameter, y = value parameter, j = static variable, z = output parameter, a[0] = array element

A

Admin • 833.24K Points
Coach

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

Code:
class Program
{
    static void Main(string[] args)
    {
        int  i ;
        for (i = 0; i < 5; i++)
        {
            Console.WriteLine(i);
        }
        Console.ReadLine();
    }
}
  • (A) 0, 1, 2, 3, 4, 5
  • (B) 0, 1, 2, 3
  • (C) 0, 1, 2, 3, 4
  • (D) 0, 0, 0, 0, 0

A

Admin • 833.24K Points
Coach

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

Code:
class Program
 {
     static void Main(string[] args)
     {
         int i;
         for ( i = 0; i < 5; i++)
         {
 
         }
         Console. WriteLine(i);
         Console. ReadLine();
     }
}
  • (A) 0, 1, 2, 3, 4, 5
  • (B) 0, 1, 2, 3, 4
  • (C) 5
  • (D) 4

A

Admin • 833.24K Points
Coach

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

Code:
class Program
 {
     static void Main(string[] args)
     {
         int i ;
         for ( i = 0; i < 5; i++)
         {
             int j = 0;
             j += i; 
             Console. WriteLine(j);
         }
         Console. WriteLine(i);
         Console. ReadLine();
     }
 }
  • (A) 0, 1, 2, 3, 4, 5, 6
  • (B) 0, 1, 2, 3, 4, 5
  • (C) 0, 1, 2, 3, 4
  • (D) 0, 1, 2, 3

A

Admin • 833.24K Points
Coach

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

Code:
static void Main(string[] args)
  {
      int i ;
      for (i = 0; i < 5; i++)
      {
          int j = 0;
          j += i; 
          Console. WriteLine(j);
      }
      Console. WriteLine( i * j);
      Console. ReadLine();
  }
  • (A) 0, 1, 6, 18, 40
  • (B) 0, 1, 5, 20, 30
  • (C) Compile time error
  • (D) 0, 1, 2, 3, 4, 5

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ