Advanced C# - Graded Quiz
9. What is an extension method in C#?
- A method that can only be used within the class where it is defined.
- A method that can be called without an object instance.
- A method that is marked with the “static” keyword.
- A method that extends the functionality of an existing class.
10. What is an anonymous type in C#?
- A type that is defined using the “class” keyword.
- A type that has a name that is generated at runtime.
- A type that is defined on the fly, without an explicit class definition.
- A type that cannot be used as a parameter or return type in a method.
11. What is the difference between "var" and "dynamic" in C#?
- There is no difference between “var” and “dynamic”.
- “Var” is used to declare a variable with an inferred type, while “dynamic” is used to declare a variable with an unknown type.
- “Var” is used to declare a variable with a known type, while “dynamic” is used to declare a variable with an inferred type.
- “Var” is used to declare a variable with an inferred type, while “dynamic” is used to declare a variable with a type that is determined at runtime.
12. What is the purpose of an anonymous type in C#?
- To define a new class with a specific set of properties.
- To define a new method with a specific signature.
- To define a new variable with a specific type.
- To define a new namespace with a specific set of classes.
13. What is the difference between the var keyword and the dynamic keyword in C#?
- The var keyword is used for strongly typed variables, while the dynamic keyword is used for weakly typed variables.
- The var keyword is used for reference types, while the dynamic keyword is used for value types.
- The var keyword is used to declare variables that can be reassigned, while the dynamic keyword is used to declare variables that are constant.
- The var keyword is used for variables whose types are determined at compile-time, while the dynamic keyword is used for variables whose types are determined at runtime.
14. What is the difference between "var" and "dynamic" in C#?
- There is no difference between “var” and “dynamic”.
- “Var” is used to declare a variable whose type is inferred by the compiler, while “dynamic” is used to declare a variable whose type can change at runtime
- “Var” is used to declare a variable of a specific type, while “dynamic” is used to declare a variable of any type.
- Both A and B.
15. What is the difference between the "var" and "dynamic" keywords in C#?
- There is no difference; they are interchangeable.
- “Var” is used for statically typed objects, while “dynamic” is used for dynamically typed objects.
- “Var” is used for dynamically typed objects, while “dynamic” is used for statically typed objects.
- “Var” is used for anonymous types, while “dynamic” is used for named types.
16. What is a delegate in C#?
- A type that represents a reference to a method with a specific signature.
- A keyword used to define a new class.
- A modifier used to indicate a method can be called from any class in the same namespace.
- A keyword used to indicate a method is a constructor.
17. What is an anonymous method in C#?
- A method with no parameters.
- A method with no name.
- A method that is defined as static.
- A method that is automatically generated by the compiler.
18. What is the purpose of an expression tree in C#?
- To represent a compiled method as a tree of nodes.
- To store metadata about a compiled assembly.
- To optimize the performance of a compiled method.
- To allow LINQ queries to be translated into code.