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 does async mean in c#?
What is difference between ienumerable and list?
When is a class declared as a class abstract?
What is getenumerator?
Why do we use polymorphism in c#?
Can you drink alcohol with a loop recorder?
How do I type a whitespace character?
In a stored procedure 4 select stmts there.If error comes in one select stmt will remaining normally executes?
What is class and object c#?
What is the difference between a variable and a literal?
Can we throw exception from catch block
What is the difference between wrapper class and primitive?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)