I encountered a coding problem today, which is very interesting.
If T1, T2, and T3 all have the same attributes, and the logic for processing these attributes is the same
There is no relationship between them. System. What should I do? The answer is as follows:
Namespace consoleapplication2 {public class T1 {public string name {Get; set;} public int count {Get; Set ;}} public class T2 {public string name {Get; set ;} public int count {Get; Set ;}} public class T3 {public string name {Get; Set ;}public int count {Get; Set ;}} public class class1 {public void printname (Dynamic t) {console. writeline (T. name);} public void printcount (ienumerable <dynamic> List) {console. writeline (list. sum (t => T. count);} public void test () {var T1 = new T1 {name = "T1", Count = 1}; var t2 = new T2 {name = "T2 ", count = 2}; var T3 = new T3 {name = "T3", Count = 3}; printname (T1); printname (T2); printname (T3 ); vaR list1 = new list <t1> {T1}; var list2 = new list <t2> {T2}; var list3 = new list <t3> {T3 }; printcount (list1); printcount (list2); printcount (list3 );}}}