C# QuizsBy digitalcollegelibrary.com / 16 March 2024 In the C# Quiz Section, every question carries 2 marks. If any question is wrong then 2 marks will be deducted. Note : - Fill the information correctly to get certified. C# Quiz 1 / 50 What does the 'Console.WriteLine()' method do in C#? Reads input from the console Writes output to the console Clears the console screen Pauses the console application 2 / 50 In C#, what is the purpose of the 'using' statement? Declares a variable Defines a loop Includes a namespace Creates an object 3 / 50 Which of the following is a value type in C#? string int Array List 4 / 50 What is the default access modifier for class members in C#? private public protected internal 5 / 50 In C#, what is the significance of the 'readonly' keyword? Denote that a method cannot be overridden Indicate that a variable's value cannot be changed after initialization Specify that a class cannot be inherited Mark a class as thread-safe 6 / 50 How can you achieve multiple inheritances in C#? Use the 'extends' keyword Use the 'implements' keyword C# doesn't support multiple inheritances Use the 'inherits' keyword 7 / 50 How can you declare a constant in C#? const int x = 5; readonly int x = 5; static int x = 5; final int x = 5; 8 / 50 How can you implement a custom exception in C#? Inherit from the 'System.Exception' class Use the 'throw' keyword with a string parameter Declare a static method named 'Exception' Utilize the 'CustomException' attribute 9 / 50 How can you implement a singleton pattern in C#? Use the 'sealed' keyword on the class Make the constructor private and provide a static method to retrieve the instance Declare a static variable and initialize it in the class constructor Use the 'final' keyword on the class 10 / 50 How does C# handle method overloading? By allowing methods with the same name but different parameter types By limiting the number of parameters in each method By preventing methods with the same name By restricting the return types of overloaded methods 11 / 50 How does C# handle multiple exceptions in a single catch block? C# does not support multiple exceptions in a single catch block Catch block can handle any exception type without specifying Use a comma-separated list of exception types Use nested try-catch blocks for each exception type 12 / 50 How does C# support polymorphism? Through method overloading and method overriding Only through method overloading Only through method overriding By using the 'sealed' keyword 13 / 50 How does the 'async' keyword affect a method in C#? Makes the method asynchronous Synchronizes the method with the main thread Specifies that the method is abstract Marks the method as deprecated 14 / 50 How does the 'using' statement contribute to resource management in C#? It frees up memory space It automatically disposes of resources when they go out of scope It allocates additional resources It prevents resource leaks 15 / 50 How does the 'using' statement simplify resource management in C#? Automatically disposes of resources when they go out of scope Allocates additional memory for resources Prevents resource leaks by using garbage collection Explicitly frees up memory space 16 / 50 How is a 'struct' different from a 'class' in C#? Structs support inheritance, while classes do not Structs are reference types, while classes are value types Structs are immutable, while classes are mutable Structs can have default constructors, while classes cannot 17 / 50 How is exception handling implemented in C#? try-catch-finally if-else switch-case do-while 18 / 50 How is a delegate different from an event in C#? Delegates are used for multithreading, while events are not Delegates can have multiple subscribers, while events cannot Events are used for multithreading, while delegates are not Delegates are static, while events are instance-specific 19 / 50 How is the 'sealed' keyword used in C#? To prevent a class from being instantiated To indicate that a class cannot be inherited To hide the implementation details of a class To make a class abstract 20 / 50 How is the 'var' keyword used in C#? Declare a variable with an inferred type Specify a variable as a variant type Create a variable with a constant value Define a variable with a dynamic type 21 / 50 How is the 'yield return' statement used in C#? To exit a loop prematurely To generate a sequence of values lazily To yield control to another thread To initiate an asynchronous operation 22 / 50 In C#, what is the 'base' keyword used for? Access the base class members Declare a base variable Initialize the base class Specify a base condition in a loop 23 / 50 What does the 'var' keyword represent in C#? Variable Variant Value Dynamic type 24 / 50 What is the 'this' keyword used for in C#? Reference the current instance of a class Reference the base class Create a new instance of a class Define a constant value 25 / 50 What is the difference between 'HashSet' and 'List' in C#? HashSet allows duplicate elements, while List does not List is unordered, while HashSet is ordered HashSet can store only integers, while List can store any data type List is faster for searching elements 26 / 50 What is the difference between 'IEnumerable' and 'IQueryable' in C#? 'IEnumerable' is used for in-memory collections, while 'IQueryable' is used for database queries 'IQueryable' is used for in-memory collections, while 'IEnumerable' is used for database queries Both are used interchangeably and have no significant difference '|Enumerable' is used for asynchronous operations, while 'IQueryable' is used for synchronous operations 27 / 50 What is the difference between 'ref' and 'out' parameters in C#? 'ref' parameters must be initialized before use, while 'out' parameters do not 'out' parameters must be initialized before use, while 'ref' parameters do not Both 'ref' and 'out' parameters are used for the same purpose 'ref' is used for value types, while 'out' is used for reference types 28 / 50 What is the difference between 'StringBuilder' and 'String' in C#? StringBuilder is immutable, while String is mutable StringBuilder is faster for concatenating strings String is faster for concatenating strings StringBuilder is used for mathematical operations 29 / 50 What is the purpose of the 'Action' delegate in C#? Represent a method with parameters and return type Handle exceptions in a method Provide a mechanism for late binding Create an asynchronous operation 30 / 50 What is the purpose of the 'async' and 'await' keywords in C#? Define asynchronous methods Synchronize threads Handle exceptions Create anonymous functions 31 / 50 What is the purpose of the 'Indexer' in C#? Access elements in a collection using square bracket notation Create an index for a database table Implement a binary search algorithm Define the starting index of an array 32 / 50 What is the purpose of the 'dynamic' keyword in C#? Define a dynamic array Declare a dynamic variable Specify a dynamic exception Delay the execution of a method 33 / 50 What is the purpose of the 'Dispose' method in C#? Release unmanaged resources Initialize a new object Sort elements in a collection Convert a string to uppercase 34 / 50 What is the purpose of the 'is' keyword in C#? Checks if two objects are the same Checks if an object is of a certain type Checks if a variable is initialized Checks if a condition is true 35 / 50 What is the purpose of the 'lock' statement in C#? Create a thread-safe singleton Declare a constant value Synchronize access to a shared resource Define a recursive function 36 / 50 What is the purpose of the 'nameof' operator in C#? Retrieve the name of a variable Determine the type of an object Get the name of a method Check if a namespace is defined 37 / 50 What is the purpose of the 'LINQ' in C#? Manipulate XML documents Write platform-specific code Query and manipulate collections of objects Define database schema 38 / 50 What is the purpose of the 'Lazy<T>' class in C#? Delay the execution of a method Lazily initialize an object Create a thread-safe singleton Handle exceptions in a lazy manner 39 / 50 What is the purpose of the 'nameof' operator in C#? Retrieve the name of a variable Determine the type of an object Get the name of a method Check if a namespace is defined 40 / 50 What is the purpose of the 'nameof' operator in C#? Retrieve the name of a variable Determine the type of an object Get the name of a method Check if a namespace is defined 41 / 50 What is the purpose of the 'Nullable<T>' struct in C#? Represent a non-nullable value type Enable value types to be assigned a value of 'null' Define a nullable reference type Create an instance of a class 42 / 50 What is the purpose of the 'params' keyword in C#? Define optional parameters in a method Pass a variable number of arguments to a method Specify access modifiers for a method Create an array of parameters 43 / 50 What is the purpose of the 'partial' keyword in C#? Define a partial class or interface Specify a partially abstract class Create a partially initialized object Partially execute a method 44 / 50 What is the purpose of the 'StringSplitOptions.RemoveEmptyEntries' parameter in the 'string.Split()' method? Removes leading and trailing whitespaces Removes empty entries from the resulting array Splits the string into lines Converts the string to uppercase 45 / 50 What is the purpose of the 'Thread.Sleep()' method in C#? Stop the execution of a thread Pause the execution of a program Delay the execution of the current thread for a specified time Terminate a thread 46 / 50 What is the purpose of the 'using static' directive in C#? Include a static class Create an instance of a class Include static members of a class directly without specifying the class name Use static variables without initialization 47 / 50 What is the purpose of the 'using' directive in C#? Include a library or namespace Declare a variable Define a class Allocate memory 48 / 50 What is the purpose of the 'yield' keyword in C#? Stop the execution of a method Delay the execution of a method Generate a sequence of values Handle exceptions 49 / 50 Which of the following is used for garbage collection in C#? delete free Dispose() GC.Collect() 50 / 50 Which of the following statements about interfaces in C# is true? Interfaces can contain fields A class can implement multiple interfaces with the same method signature Interfaces can have access modifiers Interfaces can have constructors Your score isThe average score is 55% 0% Restart quiz