An example of. Net 4.0 dynamic and Collaborative Feature Application

Source: Internet
Author: User
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 );}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.