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 the three test cases in unit testing?
What is Covariance and contravariance in C#?
Explain the difference between pass by value and pass by reference.
Where do we set the min and max pool size for connection pooling?
Explain Constructor and destructor?
What is Fragmentation and its Types?
what is software?
How does a while loop work?
What is callback method in c#?
What is string class in c#?
What is interpolation in programming?
Can we write one page in c# and other in vb in one application ?
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)