C# Exam, 25 Questions

25 Questions | Total Attempts: 199

SettingsSettingsSettings
Please wait...
C# Exam, 25 Questions

C# exam as preparation for deal with the real C# exam that conducted by our beloved customer. Prepared by: R&D Dept.


Questions and Answers
  • 1. 
    What will be the output of the C#.NET code snippet given below?int a = 10, b = 20, c = 30; int res = a < b ? a < c ? c : a : b; Console.WriteLine(res);
    • A. 

      30

    • B. 

      Compile Error / Syntax Error

    • C. 

      10

    • D. 

      20

    • E. 

      None of the above

  • 2. 
    Which of the following are the correct ways to declare a delegate for calling the function func() defined in the sample class given below? class Sample { public int func(int i, Single j) { /* Add code here. */ } }
    • A. 

      Delegate d(int i, Single j);

    • B. 

      Delegate void d(int, Single);

    • C. 

      Delegate int d(int i, Single j);

    • D. 

      Delegate void (int i, Single j);

    • E. 

      Delegate int sample.func(int i, Single j);

  • 3. 
    A derived class can stop virtual inheritance by declaring an override as
    • A. 

      Extends

    • B. 

      Inherits

    • C. 

      Sealed

    • D. 

      Inheritable

  • 4. 
    For the code snippet shown below, which of the following statements are valid? public class Generic<T> { public T Field; public void TestSub() { T i = Field + 1; } } class MyProgram { static void Main(string[] args) { Generic<int> gen = new Generic<int>(); gen.TestSub(); } }
    • A. 

      Program will generate run-time exception.

    • B. 

      Compiler will report an error: Operator '+' is not defined for types T and int.

    • C. 

      Result of addition is system-dependent.

    • D. 

      Addition will produce result 1.

  • 5. 
    For the code snippet shown below, which of the following statements are valid? public class TestIndiaBix { public void TestSub (M arg) { Console.Write(arg); } } class MyProgram { static void Main(string[] args) { TestIndiaBix bix = new TestIndiaBix(); bix.TestSub("IndonesiaBIX "); bix.TestSub(4.2f); } }
    • A. 

      Program will compile and on execution will print: IndonesiaBIX 4.2

    • B. 

      Compiler will generate an error.

    • C. 

      A non generic class Hello cannot have generic subroutine.

    • D. 

      None of the above.

  • 6. 
    Which of the following statements are correct about an ArrayList collection that implements the IEnumerable interface?
    1. The ArrayList class contains an inner class that implements the IEnumeratorinterface.
    2. An ArrayList Collection cannot be accessed simultaneously by different threads.
    3. The inner class of ArrayList can access ArrayList class's members.
    4. To access members of ArrayList from the inner class, it is necessary to passArrayList class's reference to it.
    5. Enumerator's of ArrayList Collection can manipulate the array.
    • A. 

      2 and 5 only

    • B. 

      1 and 2 only

    • C. 

      1 and 3 and 4 only

    • D. 

      All of the above

  • 7. 
    In which of the following collections is the Input/Output index-based? 
    1. Stack
    2. Queue
    3. BitArray
    4. ArrayList
    5. HashTable
     
    • A. 

      5 only

    • B. 

      1, 2 and 5 only

    • C. 

      3 and 4 only

    • D. 

      1 and 2 only

  • 8. 
    Which of the following statements is correct about the C#.NET code snippet given below? int a = 10; int b = 20; int c = 30; enum color: byte { red = a, green = b, blue = c }
    • A. 

      Variables can be assigned only to the first enum element.

    • B. 

      Variables cannot be assigned to enum elements.

    • C. 

      Variables can be assigned to any one of the enum elements.

    • D. 

      Values assigned to enum elements must always begin with 0.

  • 9. 
    Which of the following statements is correct about the C#.NET code snippet given below? switch (id) { case 6: grp = "Grp B"; break; case 13: grp = "Grp D"; break; case 1: grp = "Grp A"; break; case ls > 20: grp = "Grp E"; break ; case Else: grp = "Grp F"; break; }
    • A. 

      There is no error in this switch case statement.

    • B. 

      Compiler will report an error in case ls > 20 as well as in case Else.

    • C. 

      Compiler will report an error only in case Else.

    • D. 

      Compiler will report an error as there is no default case.

    • E. 

      The order of the first three cases should be case 1, case 6, case 13 (ascending).

  • 10. 
    What will be the output of the C#.NET code snippet given below? int i = 2, j = i; if (Convert.ToBoolean((i | j & 5) & (j - 25 * 1))) Console.WriteLine(1); else Console.WriteLine(0);
    • A. 

      1

    • B. 

      0

    • C. 

      Run time Error

    • D. 

      Compile Error

  • 11. 
    Classes and ObjectsWhich of the following will be the correct output for the C#.NET program given below?namespace IndiabixConsoleApplication { class Sample { int i; Single j; public void SetData(int i, Single j) { this.i = i; this.j = j; } public void Display() { Console.WriteLine(i + " " + j); } } class MyProgram { static void Main(string[ ] args) { Sample s1 = new Sample(); s1.SetData(36, 5.4f); s1.Display(); } } }
    • A. 

      36 5.4

    • B. 

      36 5.400000

    • C. 

      0 0.0

    • D. 

      36 5

    • E. 

      None of the above

  • 12. 
    Array. Which of the following is the correct output of the C#.NET code snippet given below? int[ , , ] a = new int[ 3, 2, 3 ]; Console.WriteLine(a.Length);
    • A. 

      20

    • B. 

      18

    • C. 

      4

    • D. 

      5

    • E. 

      10

  • 13. 
     Which of the following statements are correct about a namespace used in C#.NET?
    1. Classes must belong to a namespace, whereas structures need not.
    2. Every class, struct, enum, delegate and interlace has to belong to some or the other namespace.
    3. All elements of the namespace have to belong to one file.
    4. If not mentioned, a namespace takes the name of the current project.
    5. The namespace should be imported to be able to use the elements in it.
    • A. 

      2, 4, 5

    • B. 

      1, 3

    • C. 

      3, 5

    • D. 

      4 only

  • 14. 
    If ListBox is class present in System.Windows.Forms namespace, then which of the following statements are the correct way to create an object of ListBox Class?  
    • using System.Windows.Forms; ListBox lb = new ListBox();
    • using LBControl = System.Windows.Forms; LBControl lb = new LBControl();
    • System.Windows.Forms.ListBox lb = new System.Windows.Forms.ListBox();
    • using LBControl lb = new System.Windows.Forms.ListBox;
    • using LBControl = System.Windows.Forms.ListBox; LBControl lb = new LBControl();
    • A. 

      1, 3

    • B. 

      1, 3, 5

    • C. 

      5 only

    • D. 

      2, 4, 5

  • 15. 
     Which of the following statements is correct about the C#.NET code snippet given below?class Trial { int i; Decimal d; } struct Sample { private int x; private Single y; private Trial z; } Sample ss = new Sample(); 
    • A. 

      Ss will be created on the stack.

    • B. 

      Both ss and z will be created on the heap.

    • C. 

      Z will be created on the heap.

    • D. 

      Trial object referred by z will be created on the stack.

  • 16. 
     Which of the following will be the correct result of the statement b = a in the C#.NET code snippet given below?struct Address { private int plotno; private String city; } Address a = new Address(); Address b; b = a;
    • A. 

      Address stored in a will get copied into b.

    • B. 

      Once assignment is over a will get garbage collected.

    • C. 

      All elements of a will get copied into corresponding elements of b.

    • D. 

      Once assignment is over a will go out of scope, hence will die.

  • 17. 
     What will be the output of the C#.NET code snippet given below?namespace IndiabixConsoleApplication { class Baseclass { public void fun() { Console.Write("Base class" + " "); } } class Derived1: Baseclass { new void fun() { Console.Write("Derived1 class" + " "); } } class Derived2: Derived1 { new void fun() { Console.Write("Derived2 class" + " "); } } class Program { public static void Main(string[ ] args) { Derived2 d = new Derived2(); d.fun(); } } }
    • A. 

      Derived2 class

    • B. 

      Base class

    • C. 

      Derived1 class

    • D. 

      Base class Derived1 class Derived2 class

  • 18. 
    In an inheritance chain which of the following members of base class are accessible to the derived class members?
    1. static
    2. protected
    3. private
    4. shared
    5. public
    • A. 

      2, 5

    • B. 

      3, 4

    • C. 

      4, 5

    • D. 

      1, 3

  • 19. 
    Which of the following statements are correct?
    1. An argument passed to a ref parameter need not be initialized first.
    2. Variables passed as out arguments need to be initialized prior to being passed.
    3. Argument that uses params keyword must be the last argument of variable argument list of a method.
    4. Pass by reference eliminates the overhead of copying large data items.
    5. To use a ref parameter only the calling method must explicitly use the refkeyword.
    • A. 

      3, 4

    • B. 

      4, 5

    • C. 

      2, 3

    • D. 

      1, 2

  • 20. 
    Which of the following is the correct ways to set a value 3.14 in a variable pi such that it cannot be modified?
    • A. 

      Const float pi = 3.14F;

    • B. 

      #define pi 3.14F;

    • C. 

      Const float pi = 3.14F;

    • D. 

      Const float pi; pi = 3.14F;

  • 21. 
    Which of the following keyword is used to overload user-defined types by defining static member functions?
    • A. 

      Operatoroverload

    • B. 

      Op

    • C. 

      Opoverload

    • D. 

      Operator

  • 22. 
    A Student class has a property called rollNo and stu is a reference to a Studentobject and we want the statement stu.RollNo = 28 to fail. Which of the following options will ensure this functionality?
    • A. 

      Declare rollNo property with get, set and normal accessors.

    • B. 

      Declare rollNo property with only get accessor.

    • C. 

      Declare rollNo property with both get and set accessors.

    • D. 

      None of the above

  • 23. 
    Which of the following will be the correct output for the C#.NET code snippet given below?String s1 = "Five Star"; String s2 = "FIVE STAR"; int c; c = s1.CompareTo(s2); Console.WriteLine(c);
    • A. 

      0

    • B. 

      -1

    • C. 

      1

    • D. 

      2

  • 24. 
    Which of the following ways to create an object of the Sample class given below will work correctly?class Sample { int i; Single j; double k; public Sample (int ii, Single jj, double kk) { i = ii; j = jj; k = kk; } }
    • A. 

      Sample s2 = new Sample(10, 1.2f);

    • B. 

      Sample s3 = new Sample(10, 1.2f, 2.4);

    • C. 

      Sample s1 = new Sample();

    • D. 

      Sample s1 = new Sample(, , 2.5);

  • 25. 
    Which of the following is the root of the .NET type hierarchy?
    • A. 

      System.Type

    • B. 

      System.Object

    • C. 

      System.Base

    • D. 

      System.Root

Back to Top Back to top