A brief introduction to some small knowledge points in C #
Here are some simple small ways to use to improve the development speed.
Main method parameter address delivery
There is a time when you need to do a two-parameter operation. This makes it complicated to implement it with a return value. To explicitly reference delivery. For value types: modifier ref decoration.
Number of parameters method
When writing a method, sometimes it is often worrying about the number of parameters. For example, some of the parameters want to assume that the invocation value is the value of the string, assuming that no value is not processed.
Here is a modifier params. Assuming an indeterminate number, use an array
Params int[]numbers
Cyclical comparison of thought
To find the most of a set, use a cyclic method, such as finding the maximum value in an array. This kind of programming thought can be applied very much. To divergent thinking.
private static int Getmax (int[] arr) { int max = arr[0]; for (int i = 0; i< arr. Length; i++) { if (Max < arr[i]) { max = arr[i]; } } return max; }
Keep the decimal place problem
There are customer needs to keep two decimal places, but some happen to be a decimal. The format method is used here.
string numstr =string. Format ("{0:0.00}", 2.3);
String processing finds characters in a string
The IndexOf (Keyword,index) return value is the index at which the character is located, and index starts the query position, KeyWord is the character to look for.
String segmentation and stitching method
1, Split (New char[]{'}, stringsplitoptions.removeemptyentries);
This is in accordance with the space cut into a string array, note that the following number of parameters to remove the empty string.
2,string. Join ("", text); concatenate strings with spaces to connect elements in an array of strings
3. Convert a string into a character array tochararray ()
The writing of indexers
Some objects can be called like a call array, such as person[0]. In fact this is supposed to have an "indexer"
public string This[int Index] { get {Returnnames[index];} set {Names[index] = value;} }
Reverse Sort
Reverse-sequence thinking, with a simple array as an example.
Summarize
This section does not have too much new knowledge, is to write small knowledge points. Some ideas are also very simple, but make it clear that they can be used more than just arrays. can also be used for collections. A field for the comparison object.
Some tips for C #