Skip to content

Commit

Permalink
Added example for new-format dictionary initializer (#101)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bkoelman authored and dennisdoomen committed Oct 12, 2017
1 parent b223113 commit ee64668
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Src/Guidelines/1500_MaintainabilityGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,29 @@ Instead of:
startInfo.StandardOutput = Console.Output;
startInfo.UseShellExecute = true;

Use [Object Initializers](http://msdn.microsoft.com/en-us/library/bb384062.aspx):
var countries = new List();
countries.Add("Netherlands");
countries.Add("United States");

var countryLookupTable = new Dictionary<string, string>();
countryLookupTable.Add("NL", "Netherlands");
countryLookupTable.Add("US", "United States");

Use [Object and Collection Initializers](http://msdn.microsoft.com/en-us/library/bb384062.aspx):

var startInfo = new ProcessStartInfo("myapp.exe")
{
StandardOutput = Console.Output,
UseShellExecute = true
};

Similarly, instead of:

var countries = new List();
countries.Add("Netherlands");
countries.Add("United States");

Use collection or [dictionary initializers](http://msdn.microsoft.com/en-us/library/bb531208.aspx):


var countries = new List { "Netherlands", "United States" };

var countryLookupTable = new Dictionary<string, string>
{
["NL"] = "Netherlands",
["US"] = "United States"
};

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

Expand Down

0 comments on commit ee64668

Please sign in to comment.