1. Generics are.net Framwork 2.0 increase of new features, note the generic not syntactic sugar (var I=5;//compilers provide convenient features, called syntactic sugar),
2. The main function for a method to meet the needs of different types such as: a method to complete multiple entities query, a method to complete different types of data display, any entity into a json string, generic types of these things is very good at it, and the efficiency is very high also,
Use generic//there?
//generic methods: for the sake of a method to meet the needs of different types of
//a generic class: a class to meet the needs of different types List a Dictionary
//generic interfaces: an interface to meet the demand of different types of
//generic delegate: a delegate to meet the needs of different types of
3. The generic categories: generic class, generic methods and generic interface, generics,
4. Generic principle is -- why can support different types of generic parameter?
Generic declaration method, did not write die type, what is T? Don't know T to wait for the call to specify
Design idea: delayed declaration, all delay can be deferred, all can do, late late do
Generic method and performance with ordinary methods are consistent, is the best, but also a way to meet a number of different types,
Note: : : : : :
//WebServices WCF can't use generics, why?
//cross language, other languages also cannot use, does not support generics,
//service at the time of release must be determined, the generic not determined at compile time
5. A statement generic method name followed by Angle brackets, inside is a type parameter
Type parameter is actually a type declaration, the method is that you can use this type T.
Copy the code
Public class GenericTest
{
///
///multiple type parameters can't keyword as a parameter type name cannot be repeated
///
///
///
Public T Get
{
Throw new Exception ();
}
}
///
///generic inheritance to specify the parent class type
///
Public class ChildClass: GenericClass
{
}
///
///a generic class subclass
///
///
Public class GenericChildClass
{
}
///
///a generic class
///
///
Public class GenericClass
{
}
///
///generic interface
///
///
Public interface GenericInterface
{
}
///
///generic entrust
///
///
Public delegate void Do
Copy the code
6. Use generics
CodePudding user response:

CodePudding user response:
Return card can get 10 points available every day! Tip: you can also teach you how to faster available points enter 10000 characters