1.使用接口作为参数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace 接口作为参数
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 Circle circle = new Circle(35);
13 MyClass myclass = new MyClass(circle);
14 Console.ReadLine();
15 }
16 }
17
18 interface IShape
19 {
20 /// <summary>
21 /// Area属性
22 /// </summary>
23 int Area
24 {
25 get;
26 set;
27 }
28 void Caculate();
29 }
30 class Circle : IShape
31 {
32 /// <summary>
33 /// area字段
34 /// </summary>
35 int area = 0;
36
37 public Circle(int m_Area)
38 {
39 area = m_Area;
40 }
41
42 #region ISshape成员
43 public int Area
44 {
45 get
46 {
47 return area;
48 }
49 set
50 {
51 area = value;
52 }
53 }
54
55 public void Caculate()
56 {
57 Console.WriteLine("计算面积!");
58 }
59 #endregion
60 }
61 class MyClass
62 {
63 /// <summary>
64 /// 构造函数
65 /// </summary>
66 /// <param name="shape">IShape型参数</param>
67 public MyClass(IShape shape)
68 {
69 shape.Caculate();
70 Console.WriteLine(shape.Area);
71
72 }
73 }
74
75
76 }
77
2.使用接口作为返回值