Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How do you restrict the type which can be used in custom
generic?



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

Post New Answer

More C Sharp Interview Questions

Explain the functionalities of satellite assembly?

0 Answers   Siebel,


What is the default value of decimal in c#?

0 Answers  


Can I call a virtual method from a constructor/destructor?

0 Answers  


What is a delegate how is it type safe?

0 Answers  


What are the 3 logical operators?

0 Answers  


Which is better python or c#?

0 Answers  


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?

0 Answers  


What is managed code?

0 Answers  


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?

0 Answers  


What are the classes contained in a single .NET DLL ?

0 Answers   Siebel,


Which of these statements correctly declares a two-dimensional array in c#?

0 Answers  


Categories