首页 > 代码库 > 接口的例子
接口的例子
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ public interface IPrints { double a { set; } void Print(); void PrintPreview(); } public class IPrint { static void Main() { Console.WriteLine("Plesas select printer:"); string printerName = Console.ReadLine(); IPrints printer = null; if (printerName == "HP") { printer = new test(); } else if (printerName == "IBM") { printer = new IBMPrint(); } else if (printerName == "Epsom") { printer = new EpsomPrint(); } printer.PrintPreview(); Console.ReadKey(); printer.Print(); Console.ReadKey(); test aa = new test(); aa.testt(); Console.ReadKey(); } } public class HPPrint : IPrints { public double a { get; set; } public void PrintPreview() { Console.WriteLine(a.ToString()); } public void Print() { Console.WriteLine("this is HP Printer"); } } public class test : HPPrint { double zB = 0; public double B { set{zB=value;} get { return zB; } } HPPrint hp = new HPPrint(); public void testt() { zB = 10; hp.a = 123; hp.a += zB; hp.PrintPreview(); } } public class IBMPrint : IPrints { public double a { get; set; } public void PrintPreview() { Console.WriteLine("this is IBM Printer"); } public void Print() { Console.WriteLine("this is IBM Printer"); } } public class EpsomPrint : IPrints { public double a { get; set; } public void PrintPreview() { Console.WriteLine("this is Epsom Printer"); } public void Print() { Console.WriteLine("this is Epsom Printer"); } public void PrinSt() { Console.WriteLine("this is Epsom Printer"); } }}
接口的例子
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。