Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

c# - StringBuilder.ToString() is adding '' characters in the beginning and ending of the string

StringBuilder.ToString() is adding '' characters in the beginning and ending of the string.

Why is this?

Before calling .ToString() the string doesn't have the '' character.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Are you thinking of these backslashes here?

Example screenshot showing backslashes in the Watch window

If so, you are misreading the output: The backslashes are not actually in the string. They are only displayed here to make the representation valid according to C# syntax. If you were to output the string using Console.WriteLine, for example, it would not have backslashes.

To be fair, it is inconsistent. The debug view for the StringBuilder doesn’t have the backslashes, but the one for strings does.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...