C# Online Test

This C# Online Test simulates a real online certification exam. You will be presented with Multiple Choice Questions (MCQs) based on C# Concepts, where you will be given four options. You will select the best suitable answer for the question and then proceed to the next question without wasting given time. You will get your online test score after finishing the complete test.

1. What is the entry point of a C# console application?

a) Main
b) Start
c) Program
d) Init

2. Which of the following is a value type in C#?

a) String
b) Object
c) Char
d) Class

3. Which keyword is used to create a class inheritance in C#?

a) Extends
b) Inherits
c) Super
d) Base

4. What is the default access modifier for a class in C#?

a) public
b) private
c) internal
d) protected

5. What does the ‘static’ keyword denote in C#?

a) Constant variable
b) Temporary variable
c) Instance-independent variable
d) Global variable

6. Which of the following is NOT a loop construct in C#?

a) for
b) foreach
c) do-while
d) loop

7. What does the ‘using’ keyword do?

a) Handles exceptions
b) Includes namespaces
c) Manages memory
d) Declares interfaces

8. Which keyword is used to handle exceptions?

a) try
b) catch
c) throw
d) error

9. What is a correct way to declare a multi-dimensional array?

a) int[,] array;
b) int[][] array;
c) int[2][2] array;
d) array[,] int;

10. Which method in an object is called when the ‘new’ keyword is used?

a) finalizer
b) constructor
c) initializer
d) newMethod

11. What does the ‘?’ symbol represent in C#?

a) Null-conditional operator
b) Conditional operator
c) Nullable type
d) Unchecked type

12. Which access modifier allows a class to be accessed from any code in the assembly or any other assembly that references it?

a) public
b) private
c) internal
d) protected

13. What is encapsulation?

a) Wrapping of data and methods into a single unit
b) Inheritance from more than one base class
c) Method hiding using polymorphism
d) None of the above

14. What is the default value of the boolean type in C#?

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

15. Which operator can be used to determine the type at runtime?

a) typeof
b) sizeof
c) is
d) as

16. What is the output of string.IsNullOrEmpty(” “)?

a) True
b) False
c) Error
d) None of the above

17. What is polymorphism?

a) A compilation technique
b) Ability of different classes to provide different implementations of methods that are called through the same name
c) A type of inheritance
d) Assigning a value of one type to a variable of another type

18. What keyword is used to specify that a method overrides a base class method?

a) overloads
b) overrides
c) virtual
d) override

19. Which collection type automatically resizes as the size of the collection grows?

a) Array
b) Hashtable
c) ArrayList
d) LinkedList

20. Which of the following correctly declares a delegate?

a) delegate int MyDelegate(int x);
b) delegate int MyDelegate;
c) public delegate int MyDelegate(int x);
d) all of the above

21. What does the term ‘boxing’ refer to?

a) Encapsulating an object in a value type
b) Converting a value type to a reference type
c) Placing a value type within a System.Object
d) None of the above

22. What is an assembly in C#?

a) A class library
b) A namespace
c) A compiled code library for deployment
d) A method collection

23. What attribute must be used to explicitly hide a member of a base class?

a) hide
b) override
c) new
d) sealed

24. What is an interface in C#?

a) A class from which other classes inherit
b) A template for creating classes
c) A contract that defines a set of methods and properties
d) None of the above

25. What is LINQ?

a) Language Integrated Query
b) Long Integer Query
c) Language Integrated Quantifier
d) None of the above

26. What does the ‘readonly’ keyword do?

a) Declares a variable that cannot be modified
b) Makes a method not overridable
c) Specifies that an assembly cannot be referenced
d) None of the above

27. How do you mark a method as asynchronous?

a) async
b) await
c) asynchronous
d) None of the above

28. What does the ‘yield’ keyword do in C#?

a) Pauses the execution of a method
b) Stops the execution of a method
c) Provides a value to the enumerator object in a foreach loop
d) All of the above

29. Which is NOT a principle of Object-Oriented Programming?

a) Encapsulation
b) Inheritance
c) Polymorphism
d) Concurrency

30. What is the difference between a field and a property in C#?

a) A field is public by default, while a property is private by default.
b) A field is a variable of a class, while a property is a method that manages the field's value.
c) A property can have logic, while a field cannot.
d) B and C

31. What is exception handling in C#?

a) Managing errors at compile time
b) Handling runtime errors
c) Both a and b
d) None of the above

32. Which namespace is used for data access in C#?

a) System.Data
b) System.Access
c) System.SQL
d) System.Database

33. What does ‘Dispose’ method do?

a) Manages memory explicitly
b) Deletes unused objects
c) Frees up resources
d) All of the above

34. What is the role of the ?. operator in C#?

a) Null-conditional operator, checks for null before performing a member access
b) Multiplication operator
c) Checks if two values are not equal
d) None of the above

35. Which keyword is used to indicate that a class cannot be inherited?

a) static
b) const
c) sealed
d) final

36. What is the scope of a protected member variable?

a) Accessible only within the class it is declared
b) Accessible within the class and derived classes
c) Accessible anywhere within the application
d) None of the above

37. How are runtime polymorphism and dynamic binding achieved in C#?

a) Using virtual and override keywords
b) Using new and static keywords
c) Using public and private keywords
d) Using partial and sealed keywords

38. What is the correct way to implement error handling in C#?

a) Try-catch blocks
b) On Error Resume Next
c) Error event
d) Throw-catch

39. Which collection allows key-based access to its elements?

a) ArrayList
b) HashTable
c) Queue
d) Stack

40. What does the ‘out’ keyword do?

a) Passes a parameter by reference, not initializing it before passing
b) Forces a method to return a value
c) Declares an external method
d) All of the above

41. What does the ‘var’ keyword do in C#?

a) It declares a variable as variant type, which can hold any type of data.
b) It indicates that the type of the variable that is being declared will be automatically inferred from the expression on the right side of the initialization statement.
c) It is used to iterate over data structures.
d) None of the above

42. What is a lambda expression in C#?

a) A method that is used to create a delegate or expression tree type
b) A constant expression used for calculations
c) A type of exception
d) A data type

43. What does the ‘delegate’ keyword do?

a) It allows a method to pass arguments by reference.
b) It declares a method signature.
c) It is used to declare a variable that can hold a reference to a method.
d) None of the above

44. What is the purpose of the ‘event’ keyword?

a) To declare an event within a publisher class
b) To check for the occurrence of an event
c) To delegate the handling of an event to an external class
d) To bind data sources to data consumers

45. Which method should be overridden to compare two objects in C#?

a) ToString()
b) Equals()
c) GetHashCode()
d) CompareTo()

46. What is the purpose of the ‘ref’ keyword?

a) It passes an argument by reference.
b) It is used to state that a method parameter can be modified by the method.
c) Both A and B
d) None of the above

47. What does the ‘await’ keyword do?

a) It declares that a method includes asynchronous operations.
b) It pauses the execution of the method until the awaited task completes.
c) It starts a new asynchronous operation.
d) It ensures that a method runs synchronously.

48. What is the role of an attribute in C#?

a) To configure how methods behave at runtime
b) To add metadata to a program
c) To declare variables
d) To handle exceptions

49. Which statement is true about the static constructor in C#?

a) It is called every time an object is created.
b) It is called only once, when the first object is created or any static members are referenced.
c) It can be called directly.
d) It takes parameters.

50. What is an abstract class in C#?

a) A class that cannot be instantiated and must be inherited.
b) A class that provides complete functionality and cannot be inherited.
c) A sealed class.
d) A class that does not contain any abstract methods.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top