Introduction to some small knowledge points in C #
Here are some simple small ways to use in development to improve the speed of development.
Main method parameter address delivery
There's a time when you need to operate on two parameters, so it's complicated to implement it with a return value. To understand reference passing, for value types: modifier ref decoration.
Number of parameters method
When writing a method, sometimes it is often worrying about the number of arguments. For example, some parameters want to use the string value if the call passes the value, and if no value is passed it will not be processed. Here is a modifier params. If the number is indeterminate, use the array
Params int[]numbers
Cycle comparison Ideas
To find the most of a set, use the loop comparison method, for example, to find the maximum value in an array. This kind of programming thought can apply a lot, want 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, index begins the query position, and KeyWord is the character to find.
String cutting and stitching method
1, Split (New char[]{'}, stringsplitoptions.removeemptyentries);
This is a space cut into a string array, note that the following parameter means 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 an array of calls, such as person[0]. Actually 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 understand that they can be used more than just arrays. You can also use a collection to compare a field of an object.
Some tips for C #