2013-01-15

andrewducker: (Default)
2013-01-15 11:00 am
andrewducker: (Default)
2013-01-15 02:55 pm

Things I learned today about C#

The code I've been writing to convert a list into a comma-delimited string that consists of:
var duckerBrothers = new List<string> { "Andy", "Mike", "Hugh" };
var output = string.Empty;
foreach (var duckerBrother in duckerBrothers)
{
if (output != string.Empty)
{
output += ", ";
}

output += duckerBrother;
}

Can be rewritten as:
var duckerBrothers = new List<string> { "Andy", "Mike", "Hugh" };
var output = string.Join(",", duckerBrothers);

That's what I get for assuming that there is no built-in way of doing things.