C # string processing, object reference and inheritance (Tenth day)
It's another week. Now it's time to sum up. Let's continue to summarize what we 've learned in cloud and college. Theory: The difference between StringBuilder and String: A new instance is generated during operations (such as assignment and concatenation), while StringBuilder does not. Therefore, it is best to use StringBuilder when splicing a large number of strings or frequently performing operations on a certain String. Do not use String. If you want to operate a growing String, try not to use the String class, instead use the StringBuilder class. The two classes work in different ways: the String class is a traditional way of modifying strings. It can indeed add a String to another String, but in.. Because the system first writes two strings to the memory, then deletes the original String object, creates a String object, and reads the data in the memory and assigns it. This process takes a lot of time. The StringBuilder class under the System. Text namespace is not like this. It provides the Append method, which can be used to modify strings in the existing object, which is simple and direct. Of course, the efficiency difference between the two is usually not noticed, but if you want to add a large number of operations to a string, the time consumed by the StringBuilder class and the String class are not an order of magnitude. The int, decimal, bool, and double byte enumeration types (value types) of the object are transmitted copies, and the object (reference type) is transmitted references. If the constructor is written, all fields in the structure must be assigned a value. If the constructor is written in the structure, the default constructor is also, unlike a class, a constructor with parameters is written in the class. A non-parameter constructor is killed directly. In the constructor of the class, you do not need to assign values to all fields.