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

Could you explain the difference between func vs action vs predicate?

917


What is multithreading with .net?

1051


What you mean by inner exception in c#?

1018


In which situation(s), the use of "Delegate" is a good idea?

1019


Why do we use interface in c#?

1049


What is a bool in c#?

918


What is datetime minvalue in c#?

1082


What is the usage of Enumeration in C# Programming and is it good to use or not ?

1018


Which debugging tools you can use in the .NET ssSDK?

1018


What is the use of parse in c#?

958


What is keywords in c#?

946


Is string a class in c#?

887


Why do we use static class in c#?

964


What is constructors, explain with syntax

985


What is a static in c#?

971