The difference between string and StringBuilder

string is an alias for System.String.

StringBuilder is suitable for frequent changes to a string because it is more efficient than string.

When the value of a string variable changes, a new area needs to be allocated in memory to store the new value, the string variable points to the new value, and the old string variable value will be collected by the system garbage collector.

When the value of the StringBuilder variable changes, it only changes in the original value area, and there is no new allocation area, and the pointer of the variable does not need to be changed, and the pointer of the variable does not need to be changed, so the speed will be relatively faster.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325015123&siteId=291194637