首页 > 代码库 > S2T40.(深入.Net平台和C#编程)第四章.简答题4.刁汉生.20170406

S2T40.(深入.Net平台和C#编程)第四章.简答题4.刁汉生.20170406

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 简答题.Entity
 8 {
 9     /// <summary>
10     /// 蚂蚁类
11     /// </summary>
12     public class Ant
13     {
14         //蚂蚁名字
15         public string Name { get; set; }
16         public Ant(string name)
17         {
18             this.Name = name;
19         }
20         /// <summary>
21         /// 问好方法
22         /// </summary>
23         public void SayHi()
24         {
25             Console.WriteLine("大家好!我是一只小蚂蚁,名字叫{0}",Name);
26         }
27         /// <summary>
28         /// 找甜品方法
29         /// </summary>
30         /// <param name="des"></param>
31 
32         public void Find(Dessert des)
33         {
34             Console.WriteLine("我找到一块甜品:{0}",des.Name);
35         }
36         /// <summary>
37         /// 找伙伴方法
38         /// </summary>
39         /// <param name="count"></param>
40         public void FindPartner(int count)
41         {
42             Console.WriteLine("我招呼到{0}个同伴!",count);
43         }
44         /// <summary>
45         /// 工作方法
46         /// </summary>
47         public void Working()
48         {
49             Console.WriteLine("现在,大家搬运甜品");
50             Console.WriteLine("我们完成寻找甜品的任务!");
51         }
52        
53     }
54 }
蚂蚁类
技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 简答题.Entity
 8 {
 9     /// <summary>
10     /// 甜品类
11     /// </summary>
12     public class Dessert
13     {
14         //甜品名
15         public string Name { get; set; }
16         public Dessert(string name)
17         {
18             this.Name = name;
19         }
20     }
21 }
甜品类
技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using 简答题.Entity;
 7 
 8 namespace 简答题
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             Ant ant = new Ant("小不点");
15             ant.SayHi();
16             Dessert des = new Dessert("提拉米苏");
17             ant.Find(des);
18             ant.FindPartner(2);
19             ant.Working();
20             Console.ReadLine();
21         }
22     }
23 }
Main方法

 

S2T40.(深入.Net平台和C#编程)第四章.简答题4.刁汉生.20170406