Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

C# MCQ Set 1

1. Which of these methods of class String is used to compare two String objects for their equality?
a) equals()
b) Equals()
c) isequal()
d) Isequal()

View Answer

Answer: a [Reason:] None.

2. Which of these methods is used to compare two strings such that after comparison output returns different integer values as ( 0 for false, 1 for true)?
a) Equals ()
b) == operator
c) Compare()
d) None of the mentioned

View Answer

Answer: c [Reason:] The comparison is case sensitive in nature and hence different integer values are returned for different conditions as under : 1. zero integer (0), if string s1 equal to string s2. 2. positive integer(+1) , if string s1 greater than s2. 3. Negative integer(-1) , if string s1 is less than s2.

3. Which of these methods of class String is used to check whether a substring exists at the beginning of the particular string?
a) StartsWith()
b) EndsWith()
c) Starts()
d) ends()

View Answer

Answer: a [Reason:] Method startswith() of string class is used to check whether a substring exists in the beginning of string or not.

4. Which of these methods returns the string such that some characters which are specified to be removed from the end of strings are removed from string by mentioning the number of characters to be removed?
a) Trim()
b) Remove()
c) TrimEnd()
d) Split()

View Answer

Answer: a [Reason:] Removes a string of characters from the end of string by mentioning the number of characters to be removed from the string.

5. What is the value returned by function compareTo() if the invoking string is less than the string compared?
a) zero
b) value less than zero
c) value greater than zero
d) none of the mentioned

View Answer

Answer: b [Reason:] compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared to.

6. Which of these data type values is returned by equals() method of String class?
a) char
b) int
c) boolean
d) all of the mentioned

View Answer

Answer: c [Reason:] equals() method of string class returns boolean value true if both the strings are equal and false if they are unequal.

7. What is output of the given set of Code?

  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      { 
  5.          String c = "i love Csharp";
  6.          bool a;
  7.          a = c.StartsWith("I");
  8.          Console.WriteLine(a);
  9.          Console.ReadLine();
  10.      }
  11.  }

a) true
b) false
c) 0
d) 1

View Answer

Answer: b [Reason:] StartsWith() method is case sensitive “i” and “I” are treated differently, hence false is stored in a. Output: false

8. What is the output of the given set of Code?

  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     { 
  5.         String s1 = "I love You";
  6.         String s2 = s1;
  7.         Console.WriteLine((s1 == s2) + " " + s1.Equals(s2));
  8.         Console.ReadLine();
  9.     }
  10. }

a) true true
b) false false
c) true false
d) false true

View Answer

Answer: a [Reason:] The ‘==’ operator tests the equality of strings and since s1 = “I love You” and also s2 = s1 .So, true is returned .Similarly,Equals() returns true since the content of both s1 and s2 are equal in nature. Output : true true

9. What is output of the given set of Code?

  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      { 
  5.          String []chars = {"z", "x", "y", "z", "y"};
  6.          for (int i = 0; i < chars.Length; ++i)
  7.          for (int j = i + 1; j < chars.Length; ++j)
  8.          if(chars[i].CompareTo(chars[j]) == 0)
  9.          Console.WriteLine(chars[j]);
  10.          Console.ReadLine();
  11.      }
  12.  }

a) zx
b) xy
c) zy
d) yz

View Answer

Answer: c [Reason:] compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared To.4 Output : z y

10. What will be the output for the given set of code ?

  1. String a = "Csharp";
  2. String b = "CSHARP";
  3. int c;
  4. c = a.CompareTo(b);
  5. Console.WriteLine(c);

a) 0
b) 1
c) -2
d) -1

View Answer

Answer: d [Reason:] Negative integer -1 is returned as ‘a’ is less than ‘b’ by CompareTo() method. Output : -1

C# MCQ Set 2

1. What will be the output of the given set of code?

  1.  class maths
  2.  {
  3.      public int length;
  4.      public int breadth;
  5.      public maths(int x, int y)
  6.      {
  7.          length = x;
  8.          breadth = y;
  9.          Console.WriteLine(x + y);
  10.      }
  11.      public maths(double x, int y)
  12.      {
  13.          length = (int)x;
  14.          breadth = y;
  15.          Console.WriteLine(x * y);
  16.      }
  17.  }
  18. class Program
  19. {
  20.     static void Main(string[] args)
  21.     {
  22.         maths m = new maths(20, 40);
  23.         maths k = new maths(12.0, 12);
  24.         Console.ReadLine();
  25.     }
  26. }

a) 60, 24
b) 60, 0
c) 60, 144
d) 60, 144.0

View Answer

Answer: c [Reason:] Matching the values passed as parameters.The respective constructors are overloaded according to the matching parameter type. Output : 60 144

2. What will be the output of the given set of code?

  1.  class maths
  2.  {
  3.      public int length;
  4.      public int breadth;
  5.      public  maths(int x)
  6.      {
  7.          length = x + 1;
  8.      }
  9.      public maths(int x, int y)
  10.      {
  11.          length = x + 2;
  12.      }
  13.  }
  14.  class Program
  15.  {
  16.      static void Main(string[] args)
  17.      {
  18.          maths m = new maths(6);
  19.          maths k = new maths(6, 2);
  20.          Console.WriteLine(m.length);
  21.          Console.WriteLine(k.length);
  22.          Console.ReadLine();
  23.      }
  24.  }

a) 8, 8
b) 0, 2
c) 8, 10
d) 7, 8

View Answer

Answer: d [Reason:] None.

3. What will be the output of the given set of code?

  1.  class maths
  2.  {
  3.      public maths()
  4.      {
  5.          Console.WriteLine("constructor 1 :");
  6.      }
  7.      public maths(int x)
  8.      {
  9.          int p = 2;
  10.          int u;
  11.          u = p + x;
  12.          Console.WriteLine("constructor 2: " +u);
  13.      }
  14.  }
  15.  class Program
  16.  {
  17.      static void Main(string[] args)
  18.      {
  19.          maths k = new maths(4);
  20.          maths t = new maths();
  21.          Console.ReadLine();
  22.      }
  23.  }

a) constructor 1:
constructor 2: 6
b) constructor 2: 6
constructor 2: 6
c) constructor 2: 6
constructor 1:
d) none of the mentioned

View Answer

Answer: c [Reason:] None. Output: constructor 2: 6 constructor 1:

4. What will be the output of the given set of code?

  1. class maths
  2. {
  3.     int i;
  4.     public maths(int x)
  5.     {
  6.         i = x;
  7.         Console.WriteLine(" hello: ");
  8.     }
  9. }
  10. class maths1 : maths
  11. {
  12.     public  maths1(int x) :base(x)
  13.     {
  14.         Console.WriteLine("bye");
  15.     }
  16. }
  17. class Program
  18. {
  19.     static void Main(string[] args)
  20.     {
  21.         maths1 k = new maths1(12);
  22.         Console.ReadLine();
  23.     }
  24. }

a) hello bye
b) 12 hello
c) bye 12
d) Compile time error

View Answer

Answer: a [Reason:] None.

5. What will be the output of the given set of code?

  1.  class maths
  2.  {
  3.      int i;
  4.      public maths(int ii)
  5.      {
  6.          ii = 12;
  7.          int j = 12;
  8.          int r = ii * j;
  9.          Console.WriteLine(r);
  10.      }
  11.  }
  12.  class maths1 : maths
  13.  {
  14.      public maths1(int u) :base(u)
  15.      {
  16.          u = 13;
  17.          int h = 13;
  18.          Console.WriteLine(u + h);
  19.      }
  20.  }
  21.  class maths2 : maths1
  22.  {
  23.      public maths2(int k) :base(k)
  24.      {
  25.          k = 24;
  26.          int o = 6 ;
  27.          Console.WriteLine(k /o);
  28.      }
  29.  }
  30.  class Program
  31.  {
  32.      static void Main(string[] args)
  33.      {
  34.          maths2 t = new maths2(10);
  35.          Console.ReadLine();
  36.      }
  37.  }

a) 4, 26, 144
b) 26, 4, 144
c) 144, 26, 4
d) 0, 0, 0

View Answer

Answer: c [Reason:] None.

6. Which keyword is used to refer baseclass constructor to subclass constructor?
a) This
b) Static
c) Base
d) Extend

View Answer

Answer: c [Reason:] None.

7. When we call a constructor method among different given constructors. We match the suitable constructor by matching the name of constructor first , then the number and then the type of parameters to decide which constructor is to be overloaded.The process is also known as?
a) Method overriding
b) Inheritance
c) Polymorphism
d) Encapsulation

View Answer

Answer: c [Reason:] None.

8. Correct statement about constructor overloading in C# is?
a) Overloaded constructors have the same name as the class
b) Overloaded constructors cannot use optional arguments
c) Overloaded constructors can have different type of number of arguments as well as differ in number of arguments
d) All of the mentioned

View Answer

Answer: c [Reason:] By definition of overloaded constructors.

9. What will be the output of the given set of code?

  1.   class maths
  2.   {
  3.       static maths()
  4.       {
  5.           int s = 8;
  6.           Console.WriteLine(s);
  7.       }
  8.       public  maths(int f)
  9.       {
  10.           int h = 10;
  11.           Console.WriteLine(h);
  12.       }
  13.   }
  14.   class Program
  15.   {
  16.       static void Main(string[] args)
  17.       {
  18.           maths p = new maths(0);
  19.           Console.ReadLine();
  20.       }
  21.   }

a) 10, 10
b) 0, 10
c) 8, 10
d) 8, 8

View Answer

Answer: c [Reason:] None. Output: 8, 10

10. What will be the output of the given set of code?

  1. class maths
  2. {
  3.     int i;
  4.     public  maths(int ii)
  5.     {
  6.         ii = -25;
  7.         int g;
  8.         g = ii > 0 ? ii : ii * -1;
  9.         Console.WriteLine(g);
  10.     }
  11. }
  12. class maths1 :maths
  13. {
  14.     public  maths1(int ll) :base(ll)
  15.     {
  16.         ll = -1000;
  17.         Console.WriteLine((ll > 0 ? ll : ll * -1));
  18.     }
  19. }
  20. class Program
  21. {
  22.     static void Main(string[] args)
  23.     {
  24.         maths1 p = new maths1(6);
  25.         Console.ReadLine();
  26.     }
  27. }

a) -25
-1000
b) -1000
-25
c) 25
1000
d) None of the mentioned

View Answer

Answer: c [Reason:] None. Output : 25, 1000

C# MCQ Set 3

1. Number of constructors a class can define is ?
a) 1
b) 2
c) Any number
d) None of the mentioned

View Answer

Answer: c [Reason:] A constructor is a simple method which has the same name as the class and hence used to create object of a class. C# class can define any number of constructors. Every class contains a default constructor.

2. Correct way of defining constructor of the given class as and when objects of classes are created is:
maths s1 = new maths();
maths s2 = new maths(5, 5.4f);

a) public maths(int pp, single tt)
   {
       p = pp;
       t = tt;
   }
b) sample s;
c) public sample()
   {
      p = 0;
      t = 0.0f;
   }
  public sample(int pp, single tt)
  {
       p = pp;
       t = tt;
  }
d) s = new sample();

View Answer

Answer: a [Reason:] None.

3. Correct way to define object of sample class in which code will work correctly is:

  1.  class abc
  2.  {
  3.      int i;
  4.      float k;
  5.      public abc(int ii, float kk)
  6.      {  
  7.          i = ii;
  8.          k = kk;
  9.      }
  10.  }

a) abc s1 = new abc(1);
b) abc s1 = new abc();
c) abc s2 = new abc(1.4f);
d) abc s2 = new abc(1, 1.4f);

View Answer

Answer: d [Reason:] Return types of parameters of object of class matches with defined constructor arguments types.

4. Correct statement about constructors in C#.NET is ?
a) Constructors can be overloaded
b) Constructors are never called explicitly
c) Constructors have same name as name of the class
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

5. Which among the following is the correct statement :
Constructors are used to
a) initialize the objects
b) construct the data members
c) initialize the objects & construct the data members
d) None of the mentioned

View Answer

Answer: a [Reason:] Once the object is declared means, the constructor is also declared by default.

6. Can the method add() be overloaded in the following ways in C#?
public int add() { }
public float add(){ }
a) True
b) False
c) None of the mentioned.

View Answer

Answer: b [Reason:]C# provides feature of method overloading which means methods with same name but different types and arguments.

7. Which of the following statements is correct about constructors in C#.NET?
a) A constructor cannot be declared as private
b) A constructor cannot be overloaded
c) A constructor can be a static constructor
d) None of the mentioned

View Answer

Answer: c [Reason:] Static constructor is a constructor which can be called before any object of class is created or any static method is invoked.Static constructor is implicitly called by .net CLR.

8. What is output of the following section of code ?

  1.  class abc
  2.  {
  3.      public static void a()
  4.      {
  5.          console.writeline("first method");
  6.      }
  7.      public void b()
  8.      {
  9.          a();
  10.          console.writeline("second method");
  11.      }
  12.      public void b(int i)
  13.      {
  14.          console.writeline(i);
  15.          b();
  16.      }
  17.  }
  18.  class program
  19.  {
  20.      static void main()
  21.      {
  22.          abc k = new abc();
  23.          abc.a();
  24.          k.b(20);
  25.      }
  26.  }

a) second method
20
second method
first method
b) first method
20
first method
second method
c) first method
20
d) second method
20
first method

View Answer

Answer: b [Reason:] The class ‘abc’ first calls method()’a’ then object of class ‘k’ when calls method ‘b’ .First of all, the method ‘a’ will be executed and then executes second statement. Output :first method 20 first method second method

9. What is the return type of constructors?
a) int
b) float
c) void
d) none of the mentioned

View Answer

Answer: d [Reason:] Constructors do not have any return type not even void included in it.

10. Which method has the same name as that of its class?
a) delete
b) class
c) constructor
d) none of mentioned

View Answer

Answer: c [Reason:] By definition.

C# MCQ Set 4

1. Which operator among the following signifies the destructor operator?
a) ::
b) :
c) ~
d) &

View Answer

Answer: c [Reason:] None.

2. The method called by clients of a class to explicitly release any resources like network,connection,open files etc.When the object is no longer required?
a) Finalize()
b) End()
c) Dispose()
d) Close()

View Answer

Answer: c [Reason:] Dispose() is only method called by clients of a class to explicitly release any resource like network connection,open files etc.when object is no longer required.Hence,Dispose() provides programmer with such programming control.

3. Name a method which has the same name as that of class and which is used to destroy objects also called automatically when application is finally on process of being getting terminated.
a) Constructor
b) Finalize()
c) Destructor
d) End

View Answer

Answer: c [Reason:] Definition of destructor.

4. Which of the following statements are correct?
a) There is one garbage collector per program running in memory
b) There is one common garbage collector for all programs
c) To garbage collect an object set all references to it as null
d) Both b & c

View Answer

Answer: d [Reason:] None.

5. Operator used to free the memory when memory is allocated ?
a) new
b) free
c) delete
d) none of the mentioned

View Answer

Answer: c [Reason:] ‘New’ is used to allocate memory in the constructors.Hence,we should use ‘delete’ to free that memory.

6. Select wrong statement about destructor in C#?
a) A class can have one destructor only
b) Destructors cannot be inherited or overloaded
c) Destructors can have modifiers or parameters
d) All of the mentioned

View Answer

Answer: c [Reason:] None.

7. Output from following set of code ?

  1.   class sample
  2.   {
  3.       int i;
  4.       double k;
  5.       public sample (int ii, double kk)
  6.       {
  7.           i = ii;
  8.           k = kk;
  9.           double j = (i) + (k);
  10.           Console.WriteLine(j);
  11.       }
  12.       ~sample()
  13.       {
  14.           double j = i - k;
  15.           Console.WriteLine(j);
  16.       }
  17.   }
  18.   class Program
  19.   {
  20.       static void Main(string[] args)
  21.       {
  22.           sample s = new sample(8, 2.5);
  23.           Console.ReadLine();
  24.       }
  25.   }

a) 0 0
b) 10.5 0
c) Compile time error
d) 10.5 5.5

View Answer

Answer: d [Reason:] First constructor ‘sample’ is called and hence then destructor ‘~sample’ is evaluated. Output : 10.5, 5.5

8. What is the return type of destructor ?
a) int
b) void
c) float
d) none of the mentioned

View Answer

Answer: d [Reason:] Destructors do not have any return type not even void.

9. What is output for the following set of Code ?

  1.    class box
  2.    {
  3.        public int volume;
  4.        int width;
  5.        int height;
  6.        int length;
  7.        public box ( int w, int h, int l)
  8.        {
  9.            width = w;
  10.            height = h;
  11.            length = l;
  12.        }
  13.       public ~box()
  14.       {
  15.           volume = width * length * height;
  16.  
  17.       }
  18.  
  19.   }    
  20.   class Program
  21.   {
  22.       static void Main(string[] args)
  23.       {
  24.           box b = new box(4, 5, 9);
  25.           Console.WriteLine(b.volume);
  26.           Console.ReadLine();
  27.       }
  28.  
  29.   }

a) 0
b) 180
c) Compile time error
d) None of the mentioned

View Answer

Answer: c [Reason:] We cannot use any kind of modifier with destructor.

10. Output from selective set of code is :

  1.   class box
  2.   {
  3.       public int volume;
  4.       int width;
  5.       int height;
  6.       int length;
  7.       public box ( int w, int h, int l)
  8.       {
  9.           this.width = w;
  10.           this.height = h;
  11.           this.length = l;
  12.       }
  13.       ~ box()
  14.       {
  15.           volume = this.width * this.length * this.height;
  16.           console.writeline(volume);
  17.       }
  18.   }    
  19.   class Program
  20.   {
  21.       public  static void Main(string[] args)
  22.       {
  23.           box b = new box(4, 5, 9);
  24.           Console.ReadLine();
  25.       }
  26.   }

a) 0
b) Code executes successfully but prints nothing
c) Compile time error
d) 180

View Answer

Answer: d [Reason:] None. Output: 180.

C# MCQ Set 5

1. Select output for the following set of code :

  1.  static void Main(string[] args)
  2.  {
  3.      int i = 1, j = 2, k = 3;
  4.      do
  5.      {
  6.          Console.WriteLine((Convert.ToBoolean(Convert.ToInt32(i++))) && (Convert.ToBoolean(Convert.ToInt32(++j))));
  7.      }while (i <= 3);
  8.      Console.ReadLine();
  9.  }

a) 0 0 0
b) True True True
c) 1 1 1
d) False False False

View Answer

Answer: b [Reason:] 1 AND 1 = True.Similarly , non zero number || non zero number = True. Output:True True True.

2. Select output for the following set of code :

  1. static void Main(string[] args)
  2. {
  3.     float i = 1.0f, j = 0.05f;
  4.     do
  5.     {
  6.         Console.WriteLine(i++ - ++j);
  7.     }while (i < 2.0f && j <= 2.0f);
  8.     Console.ReadLine();
  9. }

a) 0.05
b) -0.05
c) 0.95
d) -0.04999995

View Answer

Answer: d [Reason:] None. Output : -0.04999995

3. Select the output for the following code :

  1. static void Main(string[] args)
  2. {
  3.     int i = 1, j = 5;
  4.     do
  5.     {
  6.         Console.WriteLine(i = i++ * j);
  7.     }while (i <= 10);
  8.     Console.ReadLine();
  9. }

a) 5 10 15 20 25 30 35 40 45 50
b) 5 25
c) 5 11 16 21 26 31 36 41 46 51
d) 5 30

View Answer

Answer: b [Reason:] For first step of loop i = 1 .So, i++ * j = 1 * 5 = 5 .For second step of loop i = 5 ,j = 5 .So, i++ * j = 25.As, i = 25 hence , 25 >=10 loop condition breaks. Output: 5 25.

4. For the incomplete program below, which of the code fragment will not result in an infinite loop:

  1.  static void Main(string[] args)
  2.  {
  3.      int i = 1234 ,j = 0;
  4.       /*ADD CODE HERE */
  5.      Console.WriteLine(j);
  6.  }

a)

 do
    {
        j = j + (i % 10);
    }while ((i = i / 10)!= 0);

b)

do
    {
        j = j + (i % 10);
    }while ((i / 10)!= 0);

c)

do
    {
        j = j + (i % 10);
    }while ((i % 10)!= 0);

d)

do
    {
        j = j + (i % 10);
    }while ((i/10 == 0)!= 0);

View Answer

Answer: a Output :

static void Main(string[] args)
        {
              int i = 1234,j = 0;
              do
              {
                  j = j +( i % 10);
 
              }while ((i = i / 10)!= 0);
              Console.WriteLine(j);

}

 
 

5. Select the output for the following set of code :

  1.  static void Main(string[] args)
  2.  {
  3.      long  x;
  4.      x = Convert.ToInt32(Console.ReadLine());
  5.      do
  6.      {
  7.          Console.WriteLine(x % 10);
  8.      }while ((x = x / 10) != 0);
  9.      Console.ReadLine();
  10.  }
  11.  enter x = 1234.

a) number of digits present in x
b) prints ‘1’
c) prints reverse of x
d) prints sum of digits of ‘x’

View Answer

Answer: c [Reason:] Reverse of digits using while loop statements. Output: 4321.

6. Select output for the following set of code :

  1.  static void Main(string[] args)
  2.  {
  3.      int i, s = 0, a = 1, d;
  4.      i = Convert.ToInt32(Console.ReadLine());
  5.      do
  6.      {
  7.          d = i % (2 * 4);
  8.          s = s + d * a;
  9.      }while ((Convert.ToInt32(i = i / (2 * 4))) != 0 && (Convert.ToBoolean(Convert.ToInt32((a) = (a * 10)))));
  10.      Console.WriteLine(s);
  11.      Console.ReadLine();
  12.  }
  13. enter i = 342.

a) It finds binary equivalent of i
b) It finds octal equivalent of i
c) It finds sum of digits of i
d) It finds reverse of i

View Answer

Answer: b [Reason:] None. Output : i = 342. s = 526.

7. Correct syntax for do while loop is :

a) do;
   {
    statement;
   }while (condition);
b) do(condition)
   {
     statement;
   }while;
c) do
   {
     statement;
   }while (condition)
d) do
   {
        statement;
   }while (condition);

View Answer

Answer: d [Reason:] By definition Output:do { statement; }while (condition);

8. Select the output for the following set of code :

  1. static void Main(string[] args)
  2. {
  3.     int x = 10;
  4.     do
  5.     {
  6.         Console.WriteLine( x++);
  7.     }
  8.     while(Convert.ToBoolean(5) && Convert.ToBoolean(4) && Convert.ToBoolean(3) && Convert.ToBoolean(2) && Convert.ToBoolean(1) && Convert.ToBoolean(0));    
  9.     Console.ReadLine();
  10. }

a) 13
b) 15
c) 11
d) 10

View Answer

Answer: d [Reason:] Here in do while condition ‘&&’ i.e ‘AND’operator return ‘0’ i.e false.So, as condition is false so program comes out of the loop. Output : 10.

9. Select output for the following set of code :

  1. static void Main(string[] args)
  2. {
  3.     int x;
  4.     for (x = 10; x <= 15; x++)
  5.     while (Convert.ToBoolean(Convert.ToInt32(x)))
  6.     {
  7.         do
  8.         {
  9.             Console.WriteLine(1);
  10.             if (Convert.ToBoolean(x >> 1))
  11.             continue;
  12.         }while (Convert.ToBoolean(0));
  13.         break;
  14.     }
  15.     Console.ReadLine();
  16. }

a) 0 0 0….infinite times
b) 1 1 1….infinite times
c) 1 1 1 1 1 1
d) System outofflow exception error

View Answer

Answer: c [Reason:] The execution of for loop is done for six consecutive times. Output : 1 1 1 1 1 1

10. Select the output for the following set of code :

  1. static void Main(string[] args)
  2. {
  3.     int x = 0;
  4.     do
  5.     {
  6.         x++;
  7.         if (x == 5)
  8.         {
  9.             x++;
  10.             continue;
  11.             break;
  12.         }
  13.         Console.WriteLine(x + " ");
  14.     }
  15. }while (x < 10);

a) 1 2 3 4 5
b) 10
c) 5 6 7 8 9 10
d) 1 2 3 4 5 6 7 8 9 10

View Answer

Answer: d [Reason:] The condition will print the numbers from 1 to 10 when x == 5 and when x does not satisfy if condition until x < 10. Output: 1 2 3 4 5 6 7 8 9 10 .

11. Select the output for the following set of code :

  1. static void Main(string[] args)
  2. {
  3.     int x;
  4.     for (x = 1; x <= 3; x++)
  5.     {
  6.         int j = 1;
  7.         do
  8.         {
  9.             j++;
  10.         }while (x % j == 2);
  11.         Console.WriteLine(x + " " + j);
  12.     }
  13.     Console.ReadLine();
  14. }

a) 1 12 1 3 1
b) 1 12 13 1
c) 12 22 32
d) 11 21 31

View Answer

Answer: c [Reason:] None. Output : 12 22 32.

.woocommerce-message { background-color: #98C391 !important; }