Skip to content

StringBuilder: char constructor #46052

Discussion options

You must be logged in to vote

After (painfully) realizing that certain StringBuilder constructor accepts a char, but not the one I was expecting to

What unfortunately happened was the char was implicitly cast to int. So it called the initial-capacity constructor.

Unfortunately that means adding a new constructor would break existing code. (Even if that code is probably incorrect.)

This was proposed before as #20848 and was rejected. You can watch the design review for their reasoning here: https://youtu.be/JdaQ2RP2tqM?t=6187

I think this could be something that could make sense as an analyzer. Possibly even as one of the analyzers in Microsoft.CodeAnalysis.NetAnalyzers.

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

eduherminio
Dec 15, 2020
Collaborator Author

You must be logged in to vote
3 replies
@PathogenDavid
Comment options

@eduherminio
Comment options

eduherminio Dec 15, 2020
Collaborator Author

@PathogenDavid
Comment options

Comment options

You must be logged in to vote
4 replies
@danmoseley
Comment options

@PathogenDavid
Comment options

@danmoseley
Comment options

@eduherminio
Comment options

eduherminio Dec 15, 2020
Collaborator Author

Comment options

You must be logged in to vote
0 replies
Answer selected by danmoseley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants