C # Review II (twenty first day)

Source: Internet
Author: User

Oh, and came to the conclusion of today. This time the main review of some of the string processing. Let's summarize today.

Theory:

? String string, which can be treated as a character array, an immutable attribute (through a for loop, modifying elements in a string, failure!) )。 PropertiesLength number of characters to output user nameMethodStr. Contains () Determines whether the string containsString.IsNullOrEmpty () determines whether the user input is empty? ToCharArray () converts a string to char[]? ToLower () lowercase, the return value must be received. (because: the string is immutable);? ToUpper () uppercase. ?  Equals () compares two strings for the same. Ignores case comparisons, stringcomparation.? IndexOf () If no corresponding data is found, return-1? LastIndexOf () If no corresponding data is found, return-1? Substring () intercepts the string. ? Split () splits the string. ? Join () SplitTrim () Remove spaces? Replace () ReplacementConcat (); Merging strings

The ToCharArray () string is immutable. Extract character array, invert

Startwith (a) determine if a string starts with "a"

? Note: The operation of the string must receive the return value with the variable . (The string is immutable, each time it builds a new string)

?StringBuilder Efficient string manipulationwhen a lot of string manipulation, for example, many times the concatenation of strings. the String object is immutable. Use System every time. When a method in the string class is to create a new string object in memory, it is necessary to allocate a new space for the new object. The system overhead associated with creating a new string object can be very large in situations where you need to perform repeated modifications to the string. If you want to modify the string without creating a new object, you can use System.Text. StringBuilder class. For example, using the StringBuilder class can improve performance when you concatenate many strings together in a loop. ? StringBuilder! = string//converts StringBuilder to string. with ToString ();? StringBuilder is just a tool for stitching strings, and in most cases you need to convert StringBuilder to string.StringBuilder sb = new StringBuilder ();sb. Append ()//Append stringsb. Appendline ()//Append string line wrappingsb. ToString ()//Converts the StringBuilder to a string. sb.                         Insert (); Insert Stringsb. Appendformant ()//using placeholdersReal:Receives the string entered by the user, outputting the word utilises in the reverse order of the input."abc" → "CBA" 2012Years12Month21 day " from the date string, remove the month and day, and print to the console using the program to spell html (applied to StringBuilder) Compare Application

The remaining interface applet was written down yesterday.

Program: Bird-Sparrow Sparrow Ostrich Ostrich, Penguin Penguin, Bird Can fly, ostrich, penguins can't ...

Analysis: Here will use the interface to achieve the function of bird flying. So define an interface, a bird parent class, three subclasses: The Sparrow class (which needs to inherit the bird class and use to the interface), the Ostrich class, and the Penguin class.

Creating interfaces

Only sparrows use the interface.

Sub-class:

In the main function:

Results:

Well, I'll write about it here today. Let's go ahead tomorrow. Come on!

C # Review II (twenty first day)

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.