给People添加一个扩展方法,打印出people的所有属性

View Code
 1 using System;
 2 public class ExtendMethod
 3 {
 4     public static void Main()
 5     {
 6         People p = new People();
 7         p.ToValue("小小",20,"");
 8     }
 9 }
10 public static class Extend
11 {
12     public static void ToValue(this People pp,string name,int age, string sex)
13     {
14         Console.WriteLine(name+"   "+age+"   "+sex);
15     }
16 }
17 public class People
18 {
19     public string Name
20     {get;set;}
21     public int Age
22     {get;set;}
23     public string Sex
24     {get;set;}
25 }

 

posted on 2012-08-01 19:51  午后の時間  阅读(139)  评论(0编辑  收藏  举报