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 |
Explain states of a thread in c#?
What is type class in c#?
Why do we use abstract class in c#?
What are the different approaches of passing parameters to a method?
What is callback function in c#?
what is the difference between arraylist and hash table using a simple program?
3 Answers CGI, Polaris, SunGard,
what are some characteristics of an array?
What is the full form of GAC? Explain its uses?
what are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
What is default parameter in c#?
Are classes passed by reference in c#?
What is a partial class in c#?