There are many coding methods to achieve the same purpose as Rome. It would be better if we optimize it on the basis of implementation.
(1) foreach has better execution efficiency than for statements.
The average time of foreach is only 30% of that of for. If both of them can be used, we recommend that you use foreach. In addition, writing data with for takes about 10 times as long as reading data.
(2) Avoid using ArrayList.
Because any Object to be added to the ArrayList must be of the System. Object type and the data to be removed from the ArrayList must be of the actual type. We recommend that you use a generic set to avoid packing and unpacking, thus improving performance.
(3) HashTable can be used to store a small amount of data.
(4) Declare constants for string containers. Do not enclose characters in double quotation marks ("") directly.
(5) do not use UpperCase or Lowercase to convert strings and use String. Compare instead. It can be case-insensitive for comparison.
(6) Use StringBuilder to replace the string connector "+ ".
(7) avoid declaring variables in the circulating body. Declare variables in the circulating body and initialize them in the circulating body.
(8) catch the specified Exception. Do not use general System. Exception.
(9) do not use exceptions to control program processes.
Capture exceptions are well known for performance loss. If statements are recommended to control the program flow.
(10) use using or try/finally to clear resources.
At present, we have sorted out so much.