zoukankan      html  css  js  c++  java
  • 同接口的方法不同参数个数处理

        class Program
        {
            public abstract class ParamBase { }
    
            public  class TCPParam : ParamBase
            {
                public string IP { get; set; }
                public string Port { get; set; }
            }
          public   class SeialPortParam : ParamBase
            {
                public string bote { get; set; }
            }
         
            interface ITX
            {
                void Init(ParamBase param);
    
            }
    
            class TCPTX : ITX
            {
                TCPParam _param;
    
    
                public void Init(ParamBase param)
                {
                    _param = param as TCPParam;
                    Console.WriteLine(_param.IP);
                    Console.WriteLine(_param.Port);
                }
            }
    
            class SerilPort : ITX
            {
                SeialPortParam _param;
    
    
                public void Init(ParamBase param)
                {
                    _param = param as SeialPortParam;
                    Console.WriteLine(_param.bote);
                    Console.ReadKey();
                }
            }
    
            static void Main(string[] args)
            {
                ITX tx = new TCPTX();
                TCPParam tCPParam = new TCPParam() { IP = "11", Port = "111" };
                tx.Init(tCPParam);
                tx = new SerilPort();
                SeialPortParam SerilPortParam = new SeialPortParam() { bote = "bote" };
                tx.Init(SerilPortParam);
            }
        }
    

    好用点个赞再走呗~

  • 相关阅读:
    windows 命令修改IP
    iptables_forward
    python之pickle模块
    python之os.path模块
    python之random模块
    python基础之常用模块
    python基础之测试题
    python 集合(set)基础
    python编码与解码
    python3 字符串基础
  • 原文地址:https://www.cnblogs.com/ma-nong01/p/14323432.html
Copyright © 2011-2022 走看看