Skip to content

Commit ee64668

Browse files
bkoelmandennisdoomen
authored andcommitted
Added example for new-format dictionary initializer (#101)
Also removed the second link, because it describes the old-notation dictionary initializer. The first link describes both object, list and new-notation dictionary initializers.
1 parent b223113 commit ee64668

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

Src/Guidelines/1500_MaintainabilityGuidelines.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,29 @@ Instead of:
124124
startInfo.StandardOutput = Console.Output;
125125
startInfo.UseShellExecute = true;
126126

127-
Use [Object Initializers](http://msdn.microsoft.com/en-us/library/bb384062.aspx):
127+
var countries = new List();
128+
countries.Add("Netherlands");
129+
countries.Add("United States");
130+
131+
var countryLookupTable = new Dictionary<string, string>();
132+
countryLookupTable.Add("NL", "Netherlands");
133+
countryLookupTable.Add("US", "United States");
134+
135+
Use [Object and Collection Initializers](http://msdn.microsoft.com/en-us/library/bb384062.aspx):
128136

129137
var startInfo = new ProcessStartInfo("myapp.exe")
130138
{
131139
StandardOutput = Console.Output,
132140
UseShellExecute = true
133141
};
134-
135-
Similarly, instead of:
136-
137-
var countries = new List();
138-
countries.Add("Netherlands");
139-
countries.Add("United States");
140-
141-
Use collection or [dictionary initializers](http://msdn.microsoft.com/en-us/library/bb531208.aspx):
142-
142+
143143
var countries = new List { "Netherlands", "United States" };
144+
145+
var countryLookupTable = new Dictionary<string, string>
146+
{
147+
["NL"] = "Netherlands",
148+
["US"] = "United States"
149+
};
144150

145151
### <a name="av1525"></a> Don't make explicit comparisons to `true` or `false` (AV1525) ![](images/1.png)
146152

0 commit comments

Comments
 (0)