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 functionalities of satellite assembly?
What is the default value of decimal in c#?
Can I call a virtual method from a constructor/destructor?
What is a delegate how is it type safe?
What are the 3 logical operators?
Which is better python or c#?
I was trying to use an out int parameter in one of my functions. How should I declare the variable that I am passing to it?
What is managed code?
boxing means converting value type to reference type and unboxing means converting reference type to value type.why we need boxing and unboxing?
3 Answers General Mills, Value Labs,
Which .gang of four. Design pattern is shown below?
What are the classes contained in a single .NET DLL ?
Which of these statements correctly declares a two-dimensional array 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)