Replies: 4 comments 10 replies
-
The request for a span-based indexing into a public static class DictionaryExtensions
{
public static bool ContainsKey<TValue>(this Dictionary<string, TValue> dictionary, ReadOnlySpan<char> key);
public static bool Remove<TValue>(this Dictionary<string, TValue> dictionary, ReadOnlySpan<char> key);
public static bool TryGetValue<TValue>(this Dictionary<string, TValue> dictionary, ReadOnlySpan<char> key, out TValue value);
public static T GetValue<TValue>(this Dictionary<string, TValue> dictionary, ReadOnlySpan<char> key);
} And having a decent alternative makes the proposed feature less useful. Another hurdle is that adding this feature would very likely require runtime changes. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Just a side note in case you can't wait for it to be added to .NET: my core libraries contain a |
Beta Was this translation helpful? Give feedback.
-
Moving to runtime as this appears to be an API request. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I suggest supporting ReadOnlySpan and Span as parameters in typed
Dictionary<string, TValue>
,HashSet<string>
, and so on classes.Unfortunately, we can not use
HashSet<string>.Contains
method withSpan<char>
without creating a new string on the Heap or using the string pool.We can use a string pool but it isn't easy and will copy span memory to pooled string in any way.
So I suggest enabling to define methods in classes and interfaces with additional restrictions on typed parameters.
For Example
Now that syntax is disabled, see https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0080
I suggest enabling that syntax to support additional methods when typed parameters have some additional restrictions only for that methods.
So
Contains(ReadOnlySpan<char> span)
method will have only string HashSetHashSet<string>
.Beta Was this translation helpful? Give feedback.
All reactions