zoukankan      html  css  js  c++  java
  • 关于C#中接口的概念

    接口的概念:简单地说借口就是定义了一些方法的类,但这些方法并未实现。接口可以多重继承,一个类一旦引用了一个或多个接口,就必须实现,否则是报错。

    定义接口:

    namespace 接口
    {
        interface Interface1
        {
            int getmax(int a,int b);
            void reset(string n);
        }
    }

    //类class实现接口interface1

    class Class1 : Interface1
        {
            int s;

            //实现接口的方法必须声明为public,因为有些方法在接口中是隐式共有的,所以实现也必须是共有的
            public int getmax(int m, int n
            {       
                if (m > n)
                {
                    s = m;
                    return s;             
                }
                else
                {
                    s = n;
                    return s;             
                }  
            }

             public void reset(string s)
            {
                Console.WriteLine(s);
            }

    }

    //main方法

    class Program
        {
            static void Main(string[] args)
            {
                Class1 c = new Class1();
                Console.WriteLine( c.getmax(10,6));
                c.reset("hello world");
                Console.ReadLine();
            }
        }

    运行结果如下:

    10

    hello world

  • 相关阅读:
    增加正则项Regularization to Prevent Overfitting
    feature_column、fc.input_layer以及各种类型的column如何转化
    input_fn如何读取数据
    matplotlib.pyplot如何绘制多张子图
    机器学习之杂乱笔记
    Adobe Flash Player
    LSTM/GRU-讲得非常细致
    anaconda python36 tensorflow virtualenv
    畅通工程-HZNU寒假集训
    食物链-HZUN寒假集训
  • 原文地址:https://www.cnblogs.com/niguang/p/niguang.html
Copyright © 2011-2022 走看看