Replies: 4 comments 6 replies
-
The string syntax is a very concise way to express a list of characters, e.g. " \r\n\t" instead of: [' ', '\r', '\n', '\t'] or with params:
and as a result folks use it in that way, including us. For example, here's a use with SearchValues.Create. This overload takes a private static readonly SearchValues<char> s_validChars =
SearchValues.Create("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz."); It becomes a stylistic choice whether you prefer that syntax, or if we banned the cited conversion: private static readonly SearchValues<char> s_validChars = SearchValues.Create(
'-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'_',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'.'); If we banned the use of string, either we'd be taking a source breaking change, where every use of such an API would no longer compile, or we wouldn't be able to add params to this overload, effectively dictating that developers can't use the individual character syntax if they prefer that unless they use collection expressions. I understand and can appreciate the goal of the suggestion, but I don't think it's desirable. |
Beta Was this translation helpful? Give feedback.
-
If the overload is simply taking a BTW this is also blocking us adding overloads for
You can simply write |
Beta Was this translation helpful? Give feedback.
-
Taking this suggestion would mean that application of |
Beta Was this translation helpful? Give feedback.
-
I disagree with this. When I see a string like I understand the breaking change aspect, though. |
Beta Was this translation helpful? Give feedback.
-
We have some APIs like
string.Trim
which originally receives a parameterparams char[]
. To make them efficient, we are introducingparams ROS<char>
overload to such APIs.But it immediately runs into an issue where now strings are being implicitly converted to
ROS<char>
which makes the API extremely confusing."ab123ba".Trim('a', 'b')
will go with the overload taking aparams ROS<char>
and return123
.But with strings being converted to
ROS<char>
implicitly,"ab123ba".Trim("ab")
will still go with the one taking aparams ROS<char>
, but developers would expect it returning123ba
instead of123
.I think we should disallow implicit conversion from
string
toparams ROS<char>
, and maybe disallowu8
toparams ROS<byte>
as well.See the context: dotnet/runtime#102822
/cc: @stephentoub
Beta Was this translation helpful? Give feedback.
All reactions