using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Main
{
class Program
{
static void Main(string[] args)
{
USB usb=new USB();
USBInter usbInter = usb;
PC pc = new PC();
pc.ConnectUSB(usbInter,"USB3.0");
bool state=pc.write("ABC");
if (state)
{
//Console.WriteLine(USB.USB_MEMARY);
Console.WriteLine(pc.read());
}
Console.Read();
}
}
interface USBInter
{
bool write(string data);
string read();
}
class USB : USBInter
{
public static string USB_TYPE = "USB2.0";
public static string USB_MEMARY;
#region USBInter 成员
public bool write(string data)
{
if (data == null || data.Length == 0 || data == "")
{
return false;
}
else
{
USB_MEMARY = data;
return true;
}
}
public string read()
{
if (USB_MEMARY == null || USB_MEMARY == "" || USB_MEMARY.Length == 0)
{
Console.WriteLine("数据读取失败...");
return null;
}
else
{
Console.WriteLine("数据读取成功...");
return USB_MEMARY;
}
}
#endregion
}
class PC : USBInter
{
private USBInter usbInter;
public bool ConnectUSB(USBInter usbInter,string uType)
{
if (uType == "USB3.0" || uType == "USB2.0")
{
this.usbInter = usbInter;
Console.WriteLine(uType+"已成功连接...");
return true;
}
else
{
return false;
}
}
#region USBInter 成员
public bool write(string data)
{
if (data == null || data.Length == 0 || data == "")
{
Console.WriteLine("数据写入失败...");
return false;
}
else
{
usbInter.write(data);
Console.WriteLine( "数据写入成功...");
return true;
}
}
public string read()
{
return usbInter.read();
}
#endregion
}
}
网友评论