一. 接口的类型

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

 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

相关文章:

  • 2021-10-22
  • 2022-12-23
  • 2021-05-18
  • 2021-11-24
  • 2021-10-11
  • 2021-05-17
  • 2021-11-16
猜你喜欢
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2021-12-05
  • 2021-07-20
相关资源
相似解决方案