File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change 44
55Use index initializers with dictionary.
66This elegantly prevents uninitialized dictionaries.
7+ See [ Object and Collection Initializers (C# Programming Guide)] .
78
89[ Object and Collection Initializers (C# Programming Guide) ] : https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#object-initializers-with-collection-read-only-property-initialization
910
@@ -14,19 +15,20 @@ var dict = new Dictionary<string, int>
1415 [" key2" ] = 50 ,
1516};
1617```
18+ * Good example*
1719
18- * Not so good example*
1920``` csharp
2021var dict = new Dictionary <string , int >();
2122dict [" key1" ] = 1 ;
2223dict [" key2" ] = 50 ;
2324```
25+ * Not so good example*
2426
25- * Deprecated way example*
2627``` csharp
2728var dict = new Dictionary <string , int >
2829{
2930 { " key1" , 1 },
3031 { " key2" , 50 },
3132};
3233```
34+ * Deprecated way example*
You can’t perform that action at this time.
0 commit comments