同接口的方法不同参数个数处理
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);
}
}
好用点个赞再走呗~