What do we need to get iterator implementation in IDictionary
?
#91534
-
What is blocking the following code from being a valid iteration implementation? public Dictionary<string, object> GetHeaders()
{
if (_headers == null)
{
yield return new Dictionary<string, object>();
yield break;
}
foreach(var header in _headers)
{
yield return new KeyValuePair<string, object>(header.Key, header.Value);
}
yield break;
} Note that |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsWhat is blocking the following code from being a valid iteration implementation? public Dictionary<string, object> GetHeaders()
{
if (_headers == null)
{
yield return new Dictionary<string, object>();
yield break;
}
foreach(var header in _headers)
{
yield return new KeyValuePair<string, object>(header.Key, header.Value);
}
yield break;
} Note that
|
Beta Was this translation helpful? Give feedback.
-
You can implicitly convert dictionary to IEnumerbale of KVP, but not in the opposite direction. You need to call |
Beta Was this translation helpful? Give feedback.
-
More closely to the question, the return type of iterator method should be a type that is implemented by |
Beta Was this translation helpful? Give feedback.
-
@eiriktsarpalis this is an API proposal, why did you convert that to discussion without asking?? |
Beta Was this translation helpful? Give feedback.
You haven't proposed any new APIs here. You'll need to open a new issue following the API proposal template.