C# Programming - Generics
Exercise : Generics - General Questions
- Generics - General Questions
6.
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);
}
}
7.
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.
8.
For the code snippet given below, which of the following statements are valid?
public class MyContainer<T> where T: class, IComparable
{
//Insert code here
}
- Class MyContainer requires that it's type argument must implement IComparable interface.
- Compiler will report an error for this block of code.
- There are multiple constraints on type argument to MyContainer class.
- Class MyContainer requires that its type argument must be a reference type and it must implement IComparable interface.
9.
Which of the following statements is valid about advantages of generics?
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers