. NET Learning notes----2015-07-21 (C # Basic Review 03, simple factory and abstract class)

Source: Internet
Author: User



Static void Main (string[] args) { // use process to open the specified file new ProcessStartInfo (@ "C:\Users\Administrator\Desktop\Adobe Registration machine instructions for use of. txt"); New Process (); = psi; P.start (); }

Will repeat with the previous notes, but review it again, last time not too clear

Analog Console Open File: (Review object oriented)

1. Prompt the user to enter the disk path in the console

D:\

2. Prompt the user to enter the name of the file to be opened

1.txt

So we get the D:\1.txt. This is the full path to the file.

Parent class:

     Public Abstract classFilefather { Public stringFileName {Get; Set; }         PublicFilefather (stringfileName) {             This. FileName =FileName; }         Public Abstract voidOpenFile (); }}

Txtpath sub-class:

 class   Txtpath:filefather { public  Txtpath (string   FileName):  base   public< /span> override   OpenFile () {ProcessStartInfo psi  = new  ProcessStartInfo ( Span style= "color: #0000ff;" >this  .            FileName);            Process P  = new   Process ();            P.startinfo  = PSI;        P.start (); }    }

Jpgpath sub-class:

 class   Jpgpath:filefather { public  Jpgpath (string   FileName):  base   public< /span> override   OpenFile () {ProcessStartInfo psi  = new  ProcessStartInfo ( Span style= "color: #0000ff;" >this  .            FileName);            Process P  = new   Process ();            P.startinfo  = PSI;        P.start (); }    }

Wmvpath sub-class:

 class   Wmvpath:filefather { public  Wmvpath (string   FileName):  base   public< /span> override   OpenFile () {ProcessStartInfo psi  = new  ProcessStartInfo ( Span style= "color: #0000ff;" >this  .            FileName);            Process P  = new   Process ();            P.startinfo  = PSI;        P.start (); }    }

Program Entry:

        Static voidMain (string[] args) {            //using a process to open a specified file//ProcessStartInfo psi = new ProcessStartInfo (@ "C:\Users\Administrator\Desktop\Adobe Registration machine instructions for use of. txt"); //process P = new process (); //p.startinfo = psi; //P.start ();Console.WriteLine ("Please select a disk to enter"); stringPath =Console.ReadLine (); Console.WriteLine ("Please select a file to open"); stringFileName =Console.ReadLine (); //file Full path = path + FileNameFilefather FF= GetFile (Filename,path +fileName); Ff.            OpenFile ();        Console.readkey (); }         Public StaticFilefather GetFile (stringFileName,stringFullPath) {            stringExtension =path.getextension (fileName); Filefather FF=NULL; Switch(extension) { Case ". txt": FF =NewTxtpath (FullPath);  Break;  Case ". jpg": FF =NewJpgpath (FullPath);  Break;  Case ". wmv": FF =NewWmvpath (FullPath);  Break; }            returnFF; }

Code redundancy, mainly for practicing abstract classes and abstract methods

. NET Learning notes----2015-07-21 (C # Basic Review 03, simple factory and abstract class)

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.