To create an empty sequence one uses the following
var empty = Enumerable.Empty<string> ();
Is there an equivalent for creating an empty dictionary as easily as this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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>orDictionary<TKey, TValue>since the returned instance might be modified later and would therefore invalidate the purpose…