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)