zoukankan      html  css  js  c++  java
  • interface 是什么类型?

    interface不是类型,interface是关键字,定义为 interface 是什么类型,是由其“变量”决定的。如果一定要强去理解“接口到底是什么类型”?那么它必然是引用类型(这句话与前面那句矛盾)。

    class也不是类型,只不过定义为 class 都是引用类型。

    看看实例吧:

        public interface ITest
        {
             string Text { get; set; }
        }
        
        public struct TestStruct : ITest
        {
            public string Text { get; set; }
        }
        
        public class TestClass : ITest
        {
            public string Text { get; set; }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Test1:");
                Test1();
                Console.WriteLine("Test2:");
                Test2();
                Console.ReadKey();
            }
    
            static void Test1()
            {
                TestStruct t1 = new TestStruct();
                t1.Text = "我爱辣妹";
                Func(t1);
                Console.WriteLine(t1.Text);
                TestClass t2 = new TestClass();
                t2.Text = "我爱辣妹";
                Func(t2);
                Console.WriteLine(t2.Text);
            }
    
            static void Test2()
            {
                ITest t1 = new TestStruct();
                t1.Text = "我爱辣妹";
                Func(t1);
                Console.WriteLine(t1.Text);
                ITest t2 = new TestClass();
                t2.Text = "我爱辣妹";
                Func(t2);
                Console.WriteLine(t2.Text);
            }
    
            static void Func(ITest test)
            {
                test.Text = "辣妹爱我";
            }
        }
    

  • 相关阅读:
    Rocket
    Rocket
    Rocket
    Rocket
    Rocket
    PHPstorm快捷键大全
    PHP命名规则
    第二章:第2章PHP基础语法
    第一章:初识PHP
    jQuery适用技巧笔记整合
  • 原文地址:https://www.cnblogs.com/sofire/p/1898658.html
Copyright © 2011-2022 走看看