How do you restrict the type which can be used in custom
generic?
Answer Posted / 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 |
Post New Answer View All Answers
How to rotate an Image in C#?
What is meaning of type safety in c#?
What is data set in c#?
What is the difference between values and reference types?
What does int32 mean in c#?
Do while loops yes or no c#?
How do you mark a method obsolete?
What is the difference between const and readonly in c#.net?
What is the difference between array and list in c#?
What is datatable in c#?
Can we override main method in c#?
what is the difference between interface and multiple interface?
What is an argument in c#?
What is interface inheritance in c#?
Which control cannot be placed in mdi?