0% found this document useful (0 votes)
3 views3 pages

Q17

Questions of CSharp

Uploaded by

Raj Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Q17

Questions of CSharp

Uploaded by

Raj Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q01. What type of value a method accepts when its parameter is object type?

A. Object only
B. Object and struct
C. Object, struct and enum
D. Value of any type

Q02. Which class is generic?


A. class MyClass: IComparable<MyClass> {/*... /}
B. class MyClass {public void Do<T> {/... /}}
C. class MyClass: Object {/... /}
D. class MyClass<T> {/... */}

Q03. The object type to refer to ________________________.


A. a value or variable of reference type
B. a value or variable of value type
C. a value or variable of any type
D. a value or variable of the type that implements IDisposable interface

Q04. Consider the code block (line numbers are reference)


Queue<object> queue=new Queue<object> ();
Horse myHorse=new Horse();
queue.Enqueue(myHorse);
Circle circle=(Circle)queue.Dequeue();
Which will be the possible exception from the code block?
A. At line 3, a System.InvalidCastException will be thrown
B. At line 3, a System.ArgumentException will be thrown
C. At line 4, a System.InvalidCastException will be thrown
D. At line 4, a System.ArgumentException will be thrown
Q5. You have created the following class to wrap value of any type
class MyValueContainer { public object Value {get; set;} }
Which one is the generic alternative of the class?
A. class MyValueContainer { public T Value<T> {get;set;} }
B. class MyValueContainer<T> { public object? Value {get;set;} }
C. class MyValueContainer<T> { public T Value {get;set;} }
D. class MyValueContainer { public object? Value {get;set;} }

Q06. A class designed to take parameters that can be cast to different types is a
_____________.
A. generalized class
B. generic class
C. abstract class
D. template class

Q07. What is a constructed type?


A. A generic class
B. A type that is cast to different type at run-time
C. The compiler generated new type-specific classes on demand, every type you use a
generic class with type parameter
D. A value whose actual type is resolved at run-time

Q08. Which one is not true about generics?


A. Generics make it easier to create generalized classes and methods
B. Generics improve type safety
C. Generics allows creating exception-safe methods
D. Generic classes and methods accept type parameters, which specify the types of
objects on which they operate.

Q09. Which one makes easier to create generalized classes and methods?
A. Generic
B. Object base class
C. Abstract class
D. Interface

Q10. Which one makes a generic class different from a normal class?
A. A generic class is a value type
B. A generic class does not support inheritance
C. A generic class accepts type parameters, which specify the types of data on
which they operate
D. A generic class cannot be a base class

Q11. A generic class can have multiple type parameters.


A. True
B. False

Q12. The type parameter has to be a simple class or value type.


A. True
B. False

Q13. Which one is a generic class?


A. A class that uses type parameters
B. A class designed to take parameters that can be cast to different types
C. A class that is designed to operate on any primitives
D. A class that can be cast to a value type without unboxing

Q14. You specify a type parameter in a generic class in ________________________.


A. angle brackets
B. square brackets
C. parentheses
D. curly braces

Q15. How can you limit the type parameters of a generic class to those that
implement a particular set of interfaces?
A. By using a constraint
B. By implementing interfaces
C. By using inheritance
D. All of the above

Q16. If you are defining a PrintableCollection class, you might want to ensure that
all objects stored in the class must implement IPrintable interface. How can you do
that?
A. class PrintableCollection<T: IPrintable >
B. class PrintableCollection<T where T : IPrintable>
C. class PrintableCollection<IPrintable T>
D. class PrintableCollection<T> where T : IPrintable

Q17. The type-specific versions of a generic class are referred to as


________________.
A. specific types
B. constructed types
C. typed generic
D. object types

Q18. When the CompareTo method of an IComparable object returns a value greater
than 0, what does it indicate?
A. The current instance is less than the value of the parameter
B. The current instance is equal to the value of the parameter
C. The current instance is greater than the value of the parameter
D. The CompareTo method does not return an integer value

Q19. When the CompareTo method of an IComparable object returns 0, what does it
indicate?
A. The current instance is less than the value of the parameter
B. The current instance is equal to the value of the parameter
C. The current instance is greater than the value of the parameter
D. The CompareTo method does not return an integer value

Q20. Which keyword do you use before the type parameter to create a generic
covariant interface?
A. in
B. out
C. ref
D. as

Q21. Which keyword do you use before the type parameter to create a generic
contravariant interface?
A. in
B. out
C. ref
D. as

Q22. What is a generic method?


A. A method that takes generic types as parameters
B. A method that has a return type that is a generic type
C. A method that takes generic types as parameters and that has a return type that
is a generic type
D. A method that takes generic types as parameters or that has a return type that
is a generic type or both

Q23. Which one is not a generic method?


A. T M<T> () {/..../}
B. void M<T> (T a) {/..../}
C. T M<T> (T a, T b) {/..../}
D. void M<T> () {/..../}

You might also like