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 kind of the information stored inside the assembly?
What types of object can I throw as exceptions?
Why singleton class is sealed?
Is a structure a class?
How to implement delegates in c#.net
What is the difference between namespace and class in c#?
Why is c# good for games?
What is string literal in c#?
Why do we use anonymous method in c#?
How do you sort a list in c#?
Where CANNOT Destructors be implemented ?
What is executescalar in c#?