撇号情况的正确注释代码
只是好奇你会如何评论这行代码:
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";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将其放入自己的函数中,并适当地命名该函数。这应该足够清楚了。 (而且您也可以更轻松地测试它!)
Put it into its own function, and name the function appropriately. That should be clear enough. (And you can test it more easily, too!)
我根本不会评论它。按原样来说已经足够清楚了。
如果您确实发表评论,您应该解释为什么您这样做。
例如:
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.:
我会用“不工作”来评论它。因为您在分配之前访问“customerNm”。
(您使用“customerNm+=...”,这意味着:创建一个新的字符串实例作为旧实例[尚未分配]和...的串联)。
这甚至不应该被编译。
我认为你的意思是:
其中 customerNm 是之前已经分配过一次的字符串。
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:
where customerNm is a string already assigned to once before.
不是您要问的问题,但您的代码似乎违反了 语法规则< /a>.
名称不应仅仅因为以“s”结尾而被视为复数名词。例如,如果詹姆斯有一只狗,那么它是詹姆斯的狗,而不是詹姆斯的狗。然而,如果两个名叫迈克的生活伴侣都有一只狗,那么它都是迈克的狗。
例外:如果多音节名称以“ess”或“ezz”声音结尾,则可以将其视为以“s”结尾的复数。如果莱纳斯有一只狗,它可以是莱纳斯的狗,尽管我相信莱纳斯的狗也是可以接受的。
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.