C#实现USB接口的程序代码

2007-12-17 19:05:55  来源:mzwu.com dnawo

WebjxCom提示:C#实现USB接口的程序代码.

C#实现USB接口的程序代码.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            USB usb;
            usb = new UDisk();//插入U盘
            usb.OutputFile();//从U盘读出文件
            usb.InputFile();//往U盘写入文件
            usb.Dispose();//拔出U盘
            Console.WriteLine("");
            usb = new MDisk();//插入移动硬盘
            usb.OutputFile();//从移动硬盘读出文件
            usb.InputFile();//往移动硬盘写入文件
            usb.Dispose();//拔出移动硬盘
            Console.WriteLine("");
            usb = new MP4();//插入MP4
            usb.OutputFile();//从MP4读出文件
            usb.InputFile();//往MP4写入文件
            usb.Dispose();//拔出MP4
            Console.ReadKey();
        }

        //USB接口
        public interface USB : IDisposable
        {
            void OutputFile();//读出文件
            void InputFile();//写入文件
        }

        //U盘
        public class UDisk : USB
        {
            public UDisk()
            {
                Console.WriteLine("U盘准备就绪...");
            }
            public void OutputFile()
            {
                Console.WriteLine("从U盘读出文件");
            }
            public void InputFile()
            {
                Console.WriteLine("往U盘写入文件");
            }
            public void Dispose()
            {
                Console.WriteLine("U盘已被拔出");
            }
        }

        //移动硬盘
        public class MDisk : USB
        {
            public MDisk()
            {
                Console.WriteLine("移动硬盘准备就绪...");
            }
            public void OutputFile()
            {
                Console.WriteLine("从移动硬盘读出文件");
            }
            public void InputFile()
            {
                Console.WriteLine("往移动硬盘写入文件");
            }
            public void Dispose()
            {
                Console.WriteLine("移动硬盘已被拔出");
            }
        }

        //MP4
        public class MP4 : USB
        {
            public MP4()
            {
                Console.WriteLine("MP4准备就绪...");
            }
            public void OutputFile()
            {
                Console.WriteLine("从MP4读出文件");
            }
            public void InputFile()
            {
                Console.WriteLine("往MP4写入文件");
            }
            public void Dispose()
            {
                Console.WriteLine("MP4已被拔出");
            }
        }
    }
}

更多

推荐文章