在上一篇里,我们叨逼了好多如何获取到程序集里的对象,但是对象有了,还不知道怎么调,OK,下面开始干这个对象:

首先,我们对上一篇的对象做了一些修改,以适应多种情况:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 
 5 namespace PersonMoudle
 6 {
 7     public class Person
 8     {
 9         public Person()
10         {
11             Name = "Sirius";
12             Age = 25;
13             Height = 172;
14             Sex = "Middle";
15         }
16         public Person(string name, int age, float height, string sex)
17         {
18             Name = name;
19             Age = age;
20             Height = height;
21             Sex = sex;
22         }
23 
24         public string Name { get; set; }
25         public int Age { get; set; }
26         public float Height { get; set; }
27         public string Sex { get; set; }
28 
29         #region Void
30         /// <summary>
31         /// 说话方法
32         /// </summary>
33         /// <param name="words"></param>
34         public void Speak(string words)
35         {
36             Console.WriteLine(words);
37         }
38         /// <summary>
39         /// 打电话方法
40         /// </summary>
41         /// <param name="telto">打给谁</param>
42         /// <param name="words">说什么</param>
43         public void TelSomeone(string telto, string words)
44         {
45             Console.WriteLine("Hi " + telto + ", This is sirius speaking! " + words);
46         }
47 
48         /// <summary>
49         /// 叫爹方法
50         /// </summary>
51         public void SayHi()
52         {
53             Console.WriteLine("Hi, Dad!");
54         }
55         #endregion
56 
57         private string GetMyName()
58         {
59             return Name.Trim();
60         }
61 
62         public string GetMySex()
63         {
64             return Sex;
65         }
66 
67         public List<string> BeenCity()
68         {
69             return new List<string>
70             {
71                 "Beijing",
72                 "Jinan",
73                 "NewYork"
74             };
75         }
76 
77         public List<string> BennCity(int count)
78         {
79             return new List<string>
80             {
81                 "Beijing",
82                 "Jinan",
83                 "NewYork"
84             }.Take(count).ToList();
85         }
86     }
87 }
Person类

相关文章: