The advantage of generics is that it improves the adaptability of the function and facilitates code reuse. However, in a method that supports generics, it is not known to represent the parameter type, and it is not possible to use its properties directly. Thus, this is a generic limitation that makes this generic parameter, and even the entire method, a convenience discount.
So, in a method that supports generics, a generic object is used as a parameter, and the main function is passed between different methods, like Buck. That's all.
Can't really access the properties of a generic object.
"You can use reflection," says Simon.
//propertyname, the property name to be accessed string getproperty<t> (ilist<t> listdb, string
PropertyName) {String val = "";
if (Listdb.count = = 0) return to Val; Gets the property array of the generic object by reflection propertyinfo[] Propertys = listdb[0]. GetType ().
GetProperties ();
int p = 0; foreach (PropertyInfo pi in propertys) {if pi. Name.equals (PropertyName, ComparisonType:StringComparison.CurrentCultureIgnoreCase)) {//Find PropertyName in T genus
The subscript p break in the array of sex;
} p++; } if (p = = Propertys.
Length) {throw new Exception ("Object has no corresponding property:" + PropertyName); foreach (var m in listdb) {//So, the properties of the accessible t are val = propertys[p].g Etvalue (M).
ToString () + ",";
...
}
return Val; }
Monkey Thunder.