Using Linq to objects, how to create an empty dictionary of <string, string> easily?
No there is no equivalent...
The purpose of Enumerable.Empty<T>()
is to return a "cached" instance of an empty array. So you can avoid the overhead of creating a new array (return new T[0];
).
You cannot translate this to a non-readonly structure like a IDictionary<TKey, TValue>
or Dictionary<TKey, TValue>
since the returned instance might be modified later and would therefore invalidate the purpose...
Back to year 2019, there is a way to achieve this, using:
ImmutableDictionary<TKey, TValue>.Empty
More info can be found here (last couple of posts): https://github.com/dotnet/corefx/issues/25023
What's wrong with new Dictionary<string, string>()
?