C# Programming :: Generics
-
Which one of the following classes are present System.Collections.Generic namespace?
1.stack
2.Tree
3.sorted Dictionary.
4.Sorted Array.
-
For the code snippet shown below, which of the following statements are valid?
public class GenericT> { public T Field; public void TestSub() { T i = Field + 1; } } class MyProgram { static void Main(string[] args) { Genericint> gen = new Genericint>(); gen.TestSub(); } }
-
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
-
Which of the following statements is valid about generic procedures in C#.NET?
-
For the code snippet shown below, which of the following statements are valid?
public class Testfreshergate { public void TestSub
(M arg) { Console.Write(arg); } } class MyProgram { static void Main(string[] args) { Testfreshergate gate = new Test(); gate.TestSub(" "); gate.TestSub(4.2f); } }
-
For the code snippet given below, which of the following statements is valid?
public class GenericT> { public T Field; } class Program { static void Main(string[ ] args) { Generic
g = new Generic (); g.Field = "Hello"; Console.WriteLine(g.Field); } } -
For the code snippet given below, which of the following statements are valid?
public class MyContainer
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.
-
For the code snippet given below, which of the following statements are valid?
public class MyContainer
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.
-
Which of the following statements is valid about advantages of generics?