Multi-state analog mobile hard disk inserted into the computer read and write, Method 1 parameter, Method 2 property assignment

Source: Internet
Author: User

//Multi-state analog mobile hard disk inserted into the computer read and write, Method 1 parameter, Method 2 property assignmentusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceconsoleapplication1{classProgram {Static voidMain (string[] args) {            //Multi-state analog mobile hard drive plugged into computer read/write//Mobiledisk MD = new Mobiledisk ();//the parent class abstract class cannot be instantiated, so instantiating subclasses//Udisk ud = new Udisk (); //MP3 MP = new Mp3 ();Mobilestorage MP =NewMp3 (); Computer CPU=NewComputer ();//by attributes to the parent class, outside the argument can not be passed, with the assignmentCpu. Ms = MP;//indicates that the inserted MP3 is assigned to the MS property inside the computer.//CPU.            Cpuread (MP); //CPU. Cpuwrite (MP);Cpu. Cpuread ();//Use the attribute assignment form without passing parametersCPU.            Cpuwrite ();        Console.readkey (); }         }    /// <summary>    ///abstract parent class, Removable Storage/// </summary>     Public Abstract classMobilestorage { Public Abstract voidRead ();  Public Abstract voidWrite (); }     Public classMobiledisk:mobilestorage { Public Override voidRead ()//Override can override abstract methods and virtual methods{Console.WriteLine ("The removable hard drive is reading data"); }         Public Override voidWrite () {Console.WriteLine ("The removable hard drive is writing data"); }    }     Public classUdisk:mobilestorage { Public Override voidRead () {Console.WriteLine ("USB drive is reading data"); }         Public Override voidWrite () {Console.WriteLine ("USB drive is writing data"); }    }     Public classMp3:mobilestorage { Public Override voidRead () {Console.WriteLine ("MP3 reading the data"); }         Public Override voidWrite () {Console.WriteLine ("MP3 writing the data"); }         Public voidPlaymusic () {Console.WriteLine ("MP3 can play music himself"); }    }     Public classComputer {//Method 2, take the word Gencun the passed-in parent class parameter        PrivateMobilestorage _ms;  PublicMobilestorage Ms//Field Encapsulation Properties        {            Get{return_ms;} Set{_ms =value;} }         Public voidCpuread ()//Method 1, want to get the parent class, pass parameters in the line, you can pass the sub-class come in{ms.read ();//Method 2, through the property to get the parent class, outside the argument is not passed, using the assignment        }         Public voidCpuwrite () {ms.write (); }        //Public void Cpuread (mobilestorage ms)//Method 1, want to get the parent class, pass parameters in the line, you can pass the sub-class come in//{        //Ms.        Read (); //}        //Public void Cpuwrite (mobilestorage ms)//{        //Ms.        Write (); //}    }}

Multi-state analog mobile hard disk inserted into the computer read and write, Method 1 parameter, Method 2 property assignment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.