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 |
How many parameters can a method have c#?
What is the difference between hashtable and dictionary in c#?
Explain manifest & metadata in c#.
About Virtual functions and their use ?
Explain the difference between private and shared assembly?
Can constructor have return type c#?
What is thread.sleep()?
What is concrete class in c# with example?
Which class does the remote object has to inherit?
How to Install uninstall assemblies into GAC?
What is ENUM?
10 Answers TCS, Wipro, YeshTech,
Can you have more than one namespace in c#?
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)