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 finally and finalize block?

940


4. Describe the process when we send a request URL? And who is responsible for that?

1989


Write the difference between TypeOf and GetType?

1030


Is string a data type in c#?

853


What is the use of main method in c#?

985


What is dynamic object in c#?

934


What is class in oops with example in c#?

927


Give an example of removing an element from the queue?

940


Explain the top reason to use c# language?

945


What is jagged array in c#?

1126


What is the difference between constant and readonly in c#?

929


What are the Types of JIT and what is econo-JIT

1264


How do I format a string in c#?

854


Can we inherit abstract class in c#?

926


Why do you need boxing in c#?

920