一. 接口的类型

      接口是引用类型.因此从值类型赋值给接口是需要装箱的.如下所示:

 1 class Program
 2 {
 3     static void Main(string[] args)
 4     {
 5         ISay catSay = new Cat();
 6         catSay.Say();
 7         Console.Read();
 8     }
 9 }
10 
11 interface ISay
12 {
13     void Say();
14 }
15 struct Cat : ISay
16 {
17     public void Say()
18     {
19         Console.WriteLine("Cat Say!");
20    }
21 }
View Code

相关文章: