-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add StringBuilder(Char) #20848
Comments
@iSazonov it makes sense to me. Can you please format it into a formal API proposal? It is just much easier to read and review in larger group. Thanks! |
@karelz Issue was reformatted. |
Thanks! I let area owners to check it. From my perspective it is ready for larger API review. |
This is a good point. The same problem would also exist for this piece of code: var allErrors = new StringBuilder(' ', 8); So I suggest we add these two: public partial class StringBuilder
{
public StringBuilder(char value);
public StringBuilder(char value, int repeatCount);
} @stephentoub mentioned that the sheer fact of us exposing these APIs might cause more issues, when people multi-target and now end up calling the "wrong" APIs. There is also the meta problem that this is a battle we just can't win; C# has an implicit conversion from |
Ouch, I'm surprised this didn't come up before. |
So after discussion we think it's not worth it. It's been 20 years and this isn't a widespread enough problem. |
Rationale
In PowerShell repo we got a report PowerShell/PowerShell#3457 about
It is expected that allErrors initialized with '\n' char.
Really compiler silently convert the char -> ushort -> int and use
StringBuilder(int capacity)
constructor.Sample http://ideone.com/1pPHlZ
Currently we already have method
Append(char value)
so suggestion is to add new constructorStringBuilder(char value)
.Proposed API
The text was updated successfully, but these errors were encountered: