generics: The pan is many, many, many meanings; type : Is the type, for example: int, float, double and so on data type; connected is a number of different data types, including built-in data types: The system is self-contained, defined ; custom type: it is defined by yourself, such as the class type that you define;
Why should I use generics?
In fact, in project development , there is often a method, a variety of different types of objects to invoke, the simple way is to write a method for their respective types, independent invocation, such as:
Two integer add public
int plus (int a, int b) {return
a+b;
}
Two strings connected to public string
connectstr (String str1, String str2) {return
str + str2
}
There are two functions, one is the addition of integers, one is a string connection, of course, this is very simple two functions, but you can see the common point of the two functions, are added, "+" for the string is a string connection, but you can write these two functions as a function, as follows:
Public T-plustwoobj (t objT1, T objT2) {return
objT1 + obT2;
}
The t that appears in this function is actually a placeholder, that is, this position is replaced by T; similar to the placeholder, its function is to occupy only the seat, there is no practical significance, the final position is the seat of the other people to sit, for example: T to the int to occupy, to a string of seats, to float the seat, For a custom type to occupy, the actual operation is handled by other types, other types will replace it;
This function is a public function proposed by two functions, so that it is not limited to a certain type of function to add processing, but many types of generic methods, therefore, generics have code reuse, improve research and development efficiency of the role;
... In the update