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
What are managed providers?
What are Uses of CLR
State two different types of access modifiers.
Hello! How to do this: "Create manifest utility intended for creating update content files. Application should take a set of files as input parameter and generate XML based manifest file as output one." I use C# and vs.net 2003. It's urgent! Help please, thanks. Mayana
What is generic in c#?
What are the methods in c#?
What is a Jagged Array in C#?
Can we change static variable value in c#?
Why do we need static class in c#?
How many types of collections are there in c#?
What is the default value of string in c#?
Explain what is the smallest unit of execution in .net?
How many types of namespaces available in version4?
Why singleton pattern is used in c#?
Explain lock, monitors, and mutex object in threading.