How do you restrict the type which can be used in custom
generic?
Answer / kishore.a
To restrict a type in Generic just specify the constraint
immediately following the method header, prior to the curly
braces of the method block:
For EX: you can restrict a type parameter to implement
IComparable
public class ConsoleTreeControl
{
// Generic method Show<T>
public static void Show<T>(BinaryTree<T> tree, int indent)
where T : IComparable
{
//Your Code
}
}
So this cannot implement IComparable interface.
Is This Answer Correct ? | 6 Yes | 2 No |
What do constructors do in c#?
What is arraylist?
What is default constructor in c#?
What is the purpose of private constructor in c#?
What are custom exceptions in C#?
What is lazy in c#?
What is cls, cts and clr in net?
Can abstract class instantiated c#?
What are the Uses of CLR
Is null == null c#?
What is the CTS, and how does it relate to the CLS?
Is dll a library?