simont: A picture of me in 2016 (Default)
simont ([personal profile] simont) wrote in [personal profile] andrewducker 2013-01-15 04:07 pm (UTC)

I had that problem in Python once, and found it needed fewer special-case handlers than I'd expected:
    answer = ", ".join(words[:-2] + [" and ".join(words[-2:])])
Though that does rely on Python's array slice expressions having the right edge-case behaviour when the array gets shorter than 2 elements, and I don't know if C# will do the same.

Post a comment in response:

This account has disabled anonymous posting.
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting