现在的位置: 首页 > 综合 > 正文

为类扩展方法获取该类的所有属性值

2012年12月19日 ⁄ 综合 ⁄ 共 322字 ⁄ 字号 评论关闭
View Code

 1 using System;
 2 public class GetValue
 3 {
 4     /*为People扩展一个方法ToValue
 5    要求为:能把People里面所有属性的值打印出来*/
 6     public static void Main()
 7     {
 8         People people = new People();
 9         people.Get("康熙",300);
10     }
11 }
12 public static class ToValue
13 {
14     public static void Get(this People peo,string Name,int Age)
15     {
16         Console.WriteLine(Name + Age );
17     }
18 }
19 public class People
20 {
21         
22 }

 

抱歉!评论已关闭.