Just curious how you would comment this line of code:
string customerNm = customerNm.EndsWith("s") ? customerNm+= "'" : customerNm+="'s";
Just curious how you would comment this line of code:
string customerNm = customerNm.EndsWith("s") ? customerNm+= "'" : customerNm+="'s";
// Enforce English grammar
string customerNm = customerNm.EndsWith("s") ? customerNm+= "'" : customerNm+="'s";
I would not necessarily comment it at all. It's clear enough as-is.
If you do comment it, you should explain why you do it the way you do.
E.g.:
/* Don't add "'s" for names ending on "s"
(request by Important Customer in June 1978) */
Put it into its own function, and name the function appropriately. That should be clear enough. (And you can test it more easily, too!)
string makePossessive(string customerName) {
...
}
//Apply genitive case
string customerNm = customerNm.EndsWith("s") ? customerNm+= "'" : customerNm+="'s";
I would comment it with "not working". Because you access 'customerNm' before you assign to it.
(You use "customerNm+=..." which means: create a new string instance as a concatenation of the old instance [which isn't assigned yet] and ...).
This shouldn't even get compiled.
I think what you mean is:
customerNm += customerNm.EndsWith("s") ? "'" : "'s";
where customerNm is a string already assigned to once before.
Not the question you're asking, but it looks like your code violates grammar rules.
A name should not be treated like a plural noun just because it ends in 's'. For instance, if James has a dog, it's James's dog, not James' dog. However, if two life partners named Mike have a dog, it's both Mikes' dog.
Exception: if a multisyllabic name ends in as "ess" or "ezz" sound, than it can be treated like a plural ending in 's'. If Linus has a dog, it can be Linus' dog, although I believe Linus's is also acceptable.