andrewducker: (Default)
andrewducker ([personal profile] andrewducker) wrote2013-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.
simont: A picture of me in 2016 (Default)

[personal profile] simont 2013-01-15 03:11 pm (UTC)(link)
Hmmm, so apparently the convention of not capitalising the first letter in camelCase trumps the convention of capitalising the first letter in people's surnames. Learn something new every day :-)