usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespace_08 Mobile device Storage {classProgram {Static voidMain (string[] args) {Mobiledisk MD=NewMobiledisk (); MP3 mp3=NewMp3 (); Udisk UD=NewUdisk (); Computer CPU=Newcomputer (); //incoming mobile Hard disk parameters, that is, the method of performing moving hard plate class//because the mobile storage parent class is abstract and cannot be instantiated, it can only create a new CPU generic class for read-write. and passes the abstract parent class into the CPU action method//CPU. Cpuread (MD); //CPU. Cpuwrite (MD); //the second method, defining propertiescpu.ms = MP3;//inserting the MP3 into your computerCPU. Cpuread (); Cpu. Cpuwrite (); MP3. Playmusic (); Console.readkey (); } } Abstract classMobilestorage { Public Abstract voidRead (); Public Abstract voidWrite (); } classMobiledisk:mobilestorage { Public Override voidRead () {Console.WriteLine ("The removable hard drive is reading"); } Public Override voidWrite () {Console.WriteLine ("The removable hard disk is written"); } } classUdisk:mobilestorage { Public Override voidRead () {Console.WriteLine ("USB drive is reading"); } Public Override voidWrite () {Console.WriteLine ("the USB drive is writing"); } } classMp3:mobilestorage { Public Override voidRead () {Console.WriteLine ("MP3 is reading"); } Public Override voidWrite () {Console.WriteLine ("mp3 in writing"); } Public voidPlaymusic () {Console.WriteLine ("MP3 is playing music"); } } //computers to identify various devices and perform read and write methods//Polymorphic , which is to see all the subclass objects as parent objects classComputer {//Public void Cpuread (mobilestorage ms)//{ // //The method of the parent class is executed, but the subclass overrides the parent class method, and the child class method is actually executed .//Ms. Read (); //} //Public void Cpuwrite (mobilestorage ms)//{ //Ms. Write (); //} //the second method, which defines the class property, is essentially equal to the argument//Automatic Properties Publicmobilestorage ms {Get;Set; } Public voidCpuread () { This. Ms. Read (); } Public voidCpuwrite () { This. Ms. Write (); } }}
08 Mobile Device Storage