ACCP I10 SEMESTER PCS – PROGRAMMING IN C# MODULAR QUIZ FOR Session 08 Question 1: Chose the true statements about generics in C# a b c d e Generics are used only for value types Generics are used to work with multiple data types simultaneously Generics can be implemented without a need for explicit or implicit casting Generics are verified at run-time Generics are declared with or without a type parameter Question 2: Can you match the classes and interfaces in System.Collections.Generic namespace against their corresponding descriptions? A Defines a method for iteration B Allows using a method of the IComparer interface C Defines methods to check whether the two objects are equal or not D Contains keys present in the dictionary ICompare Dictionary.KeyCollection Comparer IEnumerable IEqualityComparer collection E Allows comparison among objects of the collection Question 3: Which of the following statements about generic classes, generic methods and generic interfaces are true? a Non-generic classes cannot be inherited from generic classes b Generic classes can be declared with a class declaration following by a type parameter and optional constraints that are applied on the type parameter c Generic methods can be declared only within the generic class declaration d Generic interfaces can be used as constraints a type parameter e Generic methods can be declared with the override keyword that needs to explicitly specify the type parameter constraints Question 4: You are trying to display the area and volume of a cube by implementing a generic interface Which of the following code help you to achieve this? A B using System; using System.Collections.Generic; interface IArea { T Area(T valOne); T Volume(T valOne); } class Cube : IArea { public double Area(double valOne) { return * valOne * valOne; } public double Volume(double valOne) { return valOne * valOne * valOne; } static void Main(string[] args) { double side = 23.15; Cube objCube = new Cube(); Console.Write(“Area of cube: ”); Concole.WriteLine(objCube.Area(side)); Console.Write(“Volume of cube: ”); Console.WriteLine(objCube.Volume(side)); } } using System; using System.Collections.Generic; interface IArea(T) { T Area(T valOne); T Volume(T valOne); } class Cube : IArea { public double Area(double valOne) { return * valOne * valOne; } public double Volume(double valOne) { return valOne * valOne * valOne; } static void Main(string[] args) { double side = 23.15; Cube objCube = new Cube(); Console.Write(“Area of cube: ”); Concole.WriteLine(objCube.Area(side)); Console.Write(“Volume of cube: ”); Console.WriteLine(objCube.Volume(side)); C D } } using System; using System.Collections.Generic; interface IArea { T Area(T valOne); T Volume(T valOne); } class Cube : IArea { public double Area(double valOne) { return * valOne * valOne; } public double Volume(double valOne) { return valOne * valOne * valOne; } static void Main(string[] args) { double side = 23.15; Cube objCube = new Cube(); Console.Write(“Area of cube: ”); Concole.WriteLine(objCube.Area(side)); Console.Write(“Volume of cube: ”); Console.WriteLine(objCube.Volume(side)); } } using System; using System.Collections.Generic; interface IArea { T Area(T valOne); T Volume(T valOne); } class Cube : IArea { public double Area(double valOne) { return * valOne * valOne; } public double Volume(double valOne) { return valOne * valOne * valOne; } static void Main(string[] args) { double side = 23.15; Cube objCube = new Cube(); Console.Write(“Area of cube: ”); Concole.WriteLine(objCube.Area(side)); Console.Write(“Volume of cube: ”); Console.WriteLine(objCube.Volume(side)); } } Question 5: Which of the following statements about iterator are true? Iterators return sequentially ordered values of the same type Iterators return a fixed number of values that cannot be changed Iterators consume memory by storing the iterated in the list One of the ways to create iterators is to implement the GetEnumerator() method of the IEnumerable interface e Iterators use the yield break statement to end the iteration process a b c d Question 6: You are trying to display the different programming languages as “C”, “C++”, “Java” and “C#” Which of the following code will help you to achieve this? A B using System; class Languages : IEnumerable { string[] _language = {“C”,”C++”,”Java”,”C#”}; public IEnumerate GetEnumerator() { for(int i=0;i