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 dll and lib?

963


Can we override static class in c#?

883


Define parsing?

874


What are access modifiers in c#?

974


What does type safety mean?

1048


What is a collection class in c#?

900


Value Type and Reference Type Data type in C#?

946


Explain the process of abstraction with an example?

926


Name the two classes are required for implementing a windows service?

1032


What are delegates?

1207


What are PE(Portable Executable)?

1017


How do I start a program in c#?

970


Is typeof c#?

980


What is the difference between wrapper class and primitive?

849


What is lock in c#?

884