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

  • 相关阅读:
    基于OpenSSL自建CA和颁发SSL证书
    SSL与TLS的区别以及介绍
    Ubuntu中Nginx的安装与配置
    Openssl源代码整理学习---含P7/P10/P12说明
    动态加载js文件
    常用方法
    对reducers 理解
    小复习(3)
    如何使移动web页面禁止横屏?
    九个Console命令,让 JS 调试更简单
  • 原文地址:https://www.cnblogs.com/sofire/p/1898658.html
Copyright © 2011-2022 走看看