Generics Questions and Answers
Practice ModeShowing 10 of 32 questions
Q1
Which one of the following classes are present System.Collections.Generic namespace?
Stack
Tree
SortedDictionary
SortedArray
Answer: Option C
Q2
For the code snippet shown below, which of the following statements are valid?
public class Generic<T>
{
public T Field;
public void TestSub()
{
T i = Field + 1;
}
}
class MyProgram
{
static void Main(string[] args)
{
Generic<int> gen = new Generic<int>();
gen.TestSub();
}
}
Answer: Option D
Q3
Which of the following statements are valid about generics in .NET Framework?
Generics is a language feature.
We can create a generic class, however, we cannot create a generic interface in C#.NET.
Generics delegates are not allowed in C#.NET.
Generics are useful in collection classes in .NET framework.
None of the above
Answer: Option C
Q4
Which of the following statements is valid about generic procedures in C#.NET?
Answer: Option D
Q5
Which one of the following classes are present System.Collections.Generic namespace?
Stack
Tree
SortedDictionary
SortedArray
Answer: Option C
Q6
For the code snippet shown below, which of the following statements are valid?
public class Generic<T>
{
public T Field;
public void TestSub()
{
T i = Field + 1;
}
}
class MyProgram
{
static void Main(string[] args)
{
Generic<int> gen = new Generic<int>();
gen.TestSub();
}
}
Answer: Option D
Q7
Which of the following statements are valid about generics in .NET Framework?
Generics is a language feature.
We can create a generic class, however, we cannot create a generic interface in C#.NET.
Generics delegates are not allowed in C#.NET.
Generics are useful in collection classes in .NET framework.
None of the above
Answer: Option C
Q8
Which of the following statements is valid about generic procedures in C#.NET?
Answer: Option D
Q9
For the code snippet given below, which of the following statements is valid?
public class Generic<T>
{
public T Field;
}
class Program
{
static void Main(string[ ] args)
{
Generic<String> g = new Generic<String>();
g.Field = "Hello";
Console.WriteLine(g.Field);
}
}
Answer: Option A
Q10
For the code snippet given below, which of the following statements are valid?
public class MyContainer<T> where T: IComparabte
{
// Insert code here
}
Class MyContainer requires that it's type argument must implement IComparabte interface.
Type argument of class MyContainer must be IComparabte.
Compiler will report an error for this block of code.
This requirement on type argument is called as constraint.
Answer: Option C