1. What is meant by the term generics?
a) parameterized types
b) class
c) structure
d) interface
2. Are generics in C# are same as the generics in java and templates in C++?
a) Yes
b) No
c) May be
d) None of the mentioned
3. Choose the advantages of using generics?
a) Generics facilitate type safety
b) Generics facilitate improved performance and reduced code
c) Generics promote the usage of parameterized types
d) All of the mentioned
4. What does the following code block defines?
a) Generics class decleration
b) Decleration of variable
c) a simple class decleration
d) All of the mentioned
e) both a and b
5. What does the following code set defines?
a) Generics class decleration
b) Decleration of variable
c) Generic constructor decleration
d) All of the mentioned
6. Select the type arguement of open constructed type?
a) Gen
b) Gen
c) Gen<>
d) None of the mentioned
7. Which among the given classes present in System.Collection.Generic.namespace?
a) Stack
b) Tree
c) Sorted Array
d) All of the mentioned
8. Which of these is an correct way of defining generic method?
a) name(T1, T2, …, Tn) { /* … */ }
b) public name { /* … */ }
c) class name[T1, T2, ..., Tn] { /* … */ }
d) name{T1, T2, …, Tn} { /* … */ }
9. Which of these type parameters is used for a generic methods to return and accept any type of object?
a) K
b) N
c) T
d) V
10. Choose the correct way to call subroutine fun() of the sample class?
a) delegate void del(int i);
x s = new x();
del d = new del(ref s.x);
d(8, 2.2f);
b) delegate void del(int p, double k);
del d;
x s = new x();
d = new del(ref s.x);
d(8, 2.2f);
c) x s = new x();
delegate void d = new del(ref x);
d(8, 2.2f);
d) all of the mentioned
11. What will be the output of given code snippet?
a) 0
b) Runtime Error
c) 40
d) Compile time Error
12. What will be the output of given code snippet?
a) Compile time error
b) Csharp
c) 0
d) Run time error
a) parameterized types
b) class
c) structure
d) interface
2. Are generics in C# are same as the generics in java and templates in C++?
a) Yes
b) No
c) May be
d) None of the mentioned
3. Choose the advantages of using generics?
a) Generics facilitate type safety
b) Generics facilitate improved performance and reduced code
c) Generics promote the usage of parameterized types
d) All of the mentioned
4. What does the following code block defines?
class Gen<T> {
T ob;
}
b) Decleration of variable
c) a simple class decleration
d) All of the mentioned
e) both a and b
5. What does the following code set defines?
public Gen(T o) {
ob = o;
}
b) Decleration of variable
c) Generic constructor decleration
d) All of the mentioned
6. Select the type arguement of open constructed type?
a) Gen
b) Gen
c) Gen<>
d) None of the mentioned
7. Which among the given classes present in System.Collection.Generic.namespace?
a) Stack
b) Tree
c) Sorted Array
d) All of the mentioned
8. Which of these is an correct way of defining generic method?
a) name(T1, T2, …, Tn) { /* … */ }
b) public name { /* … */ }
c) class name[T1, T2, ..., Tn] { /* … */ }
d) name{T1, T2, …, Tn} { /* … */ }
9. Which of these type parameters is used for a generic methods to return and accept any type of object?
a) K
b) N
c) T
d) V
10. Choose the correct way to call subroutine fun() of the sample class?
class a
{
public void x(int p, double k)
{
Console.WriteLine("k : csharp!");
}
}
x s = new x();
del d = new del(ref s.x);
d(8, 2.2f);
b) delegate void del(int p, double k);
del d;
x s = new x();
d = new del(ref s.x);
d(8, 2.2f);
c) x s = new x();
delegate void d = new del(ref x);
d(8, 2.2f);
d) all of the mentioned
11. What will be the output of given code snippet?
public class Generic<T>
{
Stack<T> stk = new Stack<T>();
public void push(T obj)
{
stk.Push(obj);
}
public T pop()
{
T obj = stk.Pop();
return obj;
}
}
class Program
{
static void Main(string[] args)
{
Generic<string> g = new Generic<string>();
g.push(40);
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
b) Runtime Error
c) 40
d) Compile time Error
12. What will be the output of given code snippet?
public class Generic<T>
{
Stack<T> stk = new Stack<T>();
public void push(T obj)
{
stk.Push(obj);
}
public T pop()
{
T obj = stk.Pop();
return obj;
}
}
class Program
{
static void Main(string[] args)
{
Generic<int> g = new Generic<int>();
g.push("Csharp");
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
b) Csharp
c) 0
d) Run time error