-
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
A generic API for string-like objects #18418
Comments
I am not a big fan of string abstraction (or in general abstractions for language primitives). Abstractions add complexity and performance overhead that often cannot be afforded int he very primitive types. But I do agree that there is a problem with ToString allocations. Take a look at https:/dotnet/corefxlab/wiki/System.Text.Formatting for how we are exploring to fix that. |
I agree with @KrzysztofCwalina - I am not convinced we need the The allocations that Feel free to reopen if you have other scenarios where this would be useful. |
.NET is missing a convenient way to define a method that can take something "string-like" with minimal overhead. Most existing APIs just take
String
, meaning that callers need to callToString
, often creating full copies that are then used only to look at a few characters at the beginning. Some types that are commonly affected by this areStringBuilder
andUri
.This could be solved by adopting a common interface like
IString
for all these types, which could offer the same operations thatString
does; and implementing that interface on all standard types that have string as a public representation of any valid value.The closest existing equivalent is Java
CharSequence
.The text was updated successfully, but these errors were encountered: