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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between writeline and write in c#?

855


What does question mark mean in c#?

988


what is a structure in c#

1667


Why do we need events in c#?

978


Is hashset serializable c#?

980


What is the purpose of namespace in c#?

869


Explain the difference between and xml documentation tag?

908


What is response redirect in c#?

899


What is default boolean value in c#?

970


What are the drawbacks of extending an interface as opposed to extending a class?

886


Why do we need escape characters?

886


What is a class c#?

931


What is a boolean c#?

892


What do you mean by string objects are immutable?

997


Explain publishers and subscribers in events.

953