Initial capacity of collection types, e.g. Dictionary, List

If the default values are not documented, the reason is likely that the optimal initial capacity is an implementation detail and subject to change between framework versions. That is, you shouldn’t write code that assumes a certain default value. The constructor overloads with a capacity are for cases in which you know better than the … Read more

Assigning events in object initializer

This didn’t make C# 6 or C# 7 (since the original question), however it hasn’t been decided against. There is an issue on GitHub that tracks the language proposal. You can vote for it there, as well as follow links into previous discussion around the feature. https://github.com/dotnet/csharplang/issues/307 If you’d like to see this feature, add … Read more

Nested object initializer syntax

This syntax is called Object Initialization. C# specification clearly gives a lot of examples on this subject: 7.6.10.2 Object initializers An object initializer consists of a sequence of member initializers, enclosed by { and } tokens and separated by commas. Each member initializer must name an accessible field or property of the object being initialized, … Read more

What should my Objective-C singleton look like? [closed]

Another option is to use the +(void)initialize method. From the documentation: The runtime sends initialize to each class in a program exactly one time just before the class, or any class that inherits from it, is sent its first message from within the program. (Thus the method may never be invoked if the class is … Read more

tech