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 how to parse a datetime string?
what is the Difference between the public and private ?
What is called method in c#?
What is master page in asp net c#?
What are methods c#?
What is the meaning of extention?
What is part of a method signature in c#?
What is a dictionary in c#?
Why array is faster than arraylist in c#?
Explain the concepts of cts and cls(common language specification).
Can we have private constructor in our class file. When we are trying to create instance for the class will it create or throw error regarding that?
What do you mean by generic class 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)