1. Question: What is the purpose of the 'using' statement in C#?

    A
    To include namespaces.

    B
    To create a new variable.

    C
    To declare a class.

    D
    To manage resources and ensure disposal.

    Note: To manage resources and ensure disposal. Analysis: The using statement is used to ensure that IDisposable objects are disposed of properly, automatically releasing resources when they are no longer needed.
    1. Report
  2. Question: Which of the following is an example of polymorphism in C#?

    A
    Overloading methods.

    B
    Inheritance.

    C
    Abstract classes.

    D
    All

    Note: Polymorphism in C# can be achieved through method overloading (compile-time polymorphism) and method overriding (runtime polymorphism), both of which can involve inheritance and abstract classes.
    1. Report
  3. Question: What does the virtual keyword signify in C#?

    A
    It indicates that a method cannot be overridden.

    B
    It allows a method to be overridden in a derived class.

    C
    It creates an instance of a class.

    D
    It declares a class as abstract.

    Note: It allows a method to be overridden in a derived class. Analysis: The virtual keyword is used in a method declaration to indicate that the method can be overridden in any derived class, enabling polymorphism.
    1. Report
  4. Question: What is the purpose of the readonly keyword in C#?

    A
    It makes a field immutable after initialization.

    B
    It prevents a field from being serialized.

    C
    It restricts a variable's scope.

    D
    It creates a constant variable.

    Note: It makes a field immutable after initialization. Analysis: The readonly keyword allows a field to be assigned only during declaration or in the constructor of the class, making it immutable thereafter, but unlike const, it can be set at runtime.
    1. Report
  5. Question: Which of the following is a correct way to declare an array in C#?

    A
    int[] arr = new int[5];

    B
    int arr[5];

    C
    array int arr = new array(5);

    D
    int arr = new int[];

    Note: int[] arr = new int[5]; Analysis: This is the correct syntax for declaring an array of integers in C#. The other options either use incorrect syntax or are invalid in C#.
    1. Report
  6. Question: What will the following code print?
    int x = 10;
    Console.WriteLine(x++);

    A
    10

    B
    11

    C
    Error

    D
    0

    Note: The x++ operator is a post-increment operator, which means it returns the current value of x (10) and then increments it after the statement is executed.
    1. Report
  7. Question: In C#, what is the purpose of the sealed keyword?

    A
    It prevents a class from being inherited.

    B
    It prevents a method from being overridden

    C
    It indicates a constant value.

    D
    It marks a class as abstract.

    Note: It prevents a class from being inherited. Analysis: The sealed keyword is used to prevent further inheritance of a class, meaning no other class can derive from it. It can also be used to prevent overriding methods in a derived class.
    1. Report
  8. Question: Which method is called when an object is created from a class?

    A
    Finalizer

    B
    Destructor

    C
    Constructor

    D
    Initializer

    Note: A constructor is a special method that is called when an instance of a class is created. It is used to initialize the object's data members.
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd