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 = "辣妹爱我";
            }
        }
    

  • 相关阅读:
    DX 系列之 ComboBoxEdit
    nodejs web API 相关杂项
    解决跨域No 'Access-Control-Allow-Origin' header is present on the requested resource.
    git在本地回退
    docker容器访问宿主机IP
    mongodb+nodejs
    docker-compose控制启动顺序
    angular7 + d3 显示svg
    新建ng工程
    CSS样式
  • 原文地址:https://www.cnblogs.com/sofire/p/1898658.html
Copyright © 2011-2022 走看看