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

How can you clean up objects holding resources from within the code?

2 Answers   L&T, Wipro,


What is an assembly loader?

0 Answers  


What is a delegate?

5 Answers   Siebel Systems,


Can a class have static constructor?

0 Answers  


Can a method return multiple values in c#?

0 Answers  


Why can?t you specify the accessibility modifier for methods inside the interface?

5 Answers  


Why do we override in c#?

0 Answers  


What is difference between event and delegate in c#?

0 Answers  


What is gridview c#?

0 Answers  


Is string mutable in c#?

0 Answers  


What is anonymous types in c#?

0 Answers  


What is boolean method?

0 Answers  


Categories