C # basic knowledge point records

Source: Internet
Author: User

Some of the knowledge points used in this recent program are hereby recorded for future use! 1. Method for Testing the code execution time [csharp] Stopwatch sw = new Stopwatch (); sw. start (); // enter the code sw to be executed here. stop (); Console. writeLine ("total running time:" + sw. elapsed); Console. writeLine ("the total running time (in milliseconds) of the measurement instance:" + sw. elapsedMilliseconds); Console. writeLine ("total running time (timer scale ID):" + sw. elapsedTicks); Console. writeLine ("Whether the timer is running:" + sw. isRunning. toString (); 2. File Path and file name string truncation and replacement operation method [html] string filePath = @ "E: \ Randy0528 \ Chinese directory \ JustTest.rar"; Respo Neuron. Write ("file path:" + filePath); Response. Write ("<br/> change the extension of the path string. <Br/> "); Response. write (System. IO. path. changeExtension (filePath, "txt"); Response. write ("<br/> returns the directory information of the specified path string .. <Br/> "); Response. Write (System. IO. Path. GetDirectoryName (filePath); Response. Write (" <br/> return the extension of the specified Path string. <Br/> "); Response. write (System. IO. path. getExtension (filePath); Response. write ("<br/> returns the name and extension of the specified path string. <Br/> "); Response. write (System. IO. path. getFileName (filePath); Response. write ("<br/> returns the file name of the specified path string without the extension. <Br/> "); Response. Write (System. IO. Path. GetFileNameWithoutExtension (filePath); Response. Write (" <br/> get the root directory information of the specified Path. <Br/> "); Response. Write (System. IO. Path. GetPathRoot (filePath); Response. Write (" <br/> return the random folder name or file name. <Br/> "); Response. write (System. IO. path. getRandomFileName (); Response. write ("<br/> create a temporary file named zero byte on the disk and return the complete path of the file. <Br/> "); Response. Write (System. IO. Path. GetTempFileName (); Response. Write (" <br/> return the Path of the temporary folder of the current System. <Br/> "); Response. Write (System. IO. Path. GetTempPath (); Response. Write (" <br/> determine whether the Path includes the file extension. <Br/> "); Response. write (System. IO. path. hasExtension (filePath); Response. write ("<br/> gets a value that indicates whether the specified path string contains absolute or relative path information. <Br/> "); Response. write (System. IO. path. isPathRooted (filePath); 3. System. IO. streamWriter writes a file line feed [html] StreamWriter swPdfChange = new StreamWriter (txtfilename, false, Encoding. UTF8); swPdfChange. write ("baPWV:" + str1 + "" + str2 + "\ r \ nABI:" + str3); swPdfChange. close (); [csharp] StreamWriter swPdfChange = new StreamWriter (txtfilename, false, Encoding. UTF8); swPdfChange. writeLine ("baPWV:" + str1 + "" + str2); swPdfChange. writeLine ("ABI:" + str3); swPdfChange. close (); 4. console with parameter program [csharp] using System; using System. collections. generic; using System. linq; using System. text; namespace _ 1 {class Program {static void Main (string [] args) {if (args. length <1) {Console. writeLine ("Enter the parameter-a-v \" a s \ "");} else {foreach (string key in args) {if (key = "a s ") {Console. writeLine ("This is 'a s' parameters");} else if (key = "-a") {Console. writeLine ("This is 'A' parameters");} else if (key = "-v") {Console. writeLine ("This is 'V' parameters");} else {Console. writeLine ("parameter error ");}}}}}}

Related Article

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.