Interface

作者: 若水生花啊啊啊 | 来源:发表于2019-04-21 19:38 被阅读0次

结构定义了一个共同 的约定,在继承和使用的时候可以使用不同的方案实现相同的目的。而且可以实现多重的继承。在实现接口的时候其访问类型必须为public。

class Program
    {
        static void Main(string[] args)
        {
            Person P1 = new Person();
            P1.name = "Wang";
            Person P2 = new Person();
            Console.WriteLine("The result of the P1 compare to P2 {0}", P1.CompareToTst(P2));

            IComparableTst If_P1 = new Person();
            
            IComparableTst If_P2 = new Person();
            Console.WriteLine("The result of the If_P1 compare to If_P2 {0}", If_P1.CompareToTst(If_P2));
            Console.ReadKey();
        }
    }

    class Person: IComparableTst
    {
        public string name;
        public bool sex;
        public int age;
        public Person()
        {
            name = "Lee";
            sex = false;
            age = 18;
        }
        public int CompareToTst(object obj)
        {
            Person p = (Person)obj;
            int st = 0;
            if (this.age == p.age) st = 0;
            if (this.age < p.age) st = -1;
            if (this.age > p.age) st = 1;
            return st;
        }
    }

    interface IComparableTst
    {
        int CompareToTst(object obj);

相关文章

  • interface{} 与 []interface{}

    简介 基于可以对interface{}赋值任何类型的变量,很多人会尝试如下的代码: 很不幸会导致错误: 于是问题来...

  • Interface

    Interface is a group of method signatures, continuin with...

  • Interface

    为什么interface中的变量都是static public final? 首先接口是一种高度抽象的"模版",,...

  • interface

    接口用于定义对象的 '轮廓' 但是如果我们直接传入一个对象字面量进去,ts就会报错, 因为ts对对象字面量检测更加...

  • interface

    http://blog.csdn.net/justaipanda/article/details/43155949...

  • @interface

    深入理解Java:注解(Annotation)自定义注解入门http://www.cnblogs.com/peid...

  • Interface

    4.1 Comma Separated Value. *Comma Separated Value *or CSV...

  • interface

    由于基础很差不太明白interface到底是个啥接口上我一直不太理解,插上就通电了......通电什么意思 插曲最...

  • interface

    java语言里面使用interface来声明一个接口,接口其实是一个特殊的抽象类,在接口里面的方法全部都是抽象的。...

  • @Interface

    1.@Retention:RetentionPolicy.SOURCE:检查,源文件存在,编译丢失Retentio...

网友评论

      本文标题:Interface

      本文链接:https://www.haomeiwen.com/subject/npgjgqtx.html