撇号情况的正确注释代码

发布于 2024-08-03 02:42:17 字数 133 浏览 8 评论 0原文

只是好奇你会如何评论这行代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

对你再特殊 2024-08-10 02:42:17

将其放入自己的函数中,并适当地命名该函数。这应该足够清楚了。 (而且您也可以更轻松地测试它!)

string makePossessive(string customerName) {
    ...
}

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) {
    ...
}
ι不睡觉的鱼゛ 2024-08-10 02:42:17

我根本不会评论它。按原样来说已经足够清楚了。

如果您确实发表评论,您应该解释为什么您这样做。

例如:

/* Don't add "'s" for names ending on "s" 
  (request by Important Customer in June 1978) */

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) */
待"谢繁草 2024-08-10 02:42:17

我会用“不工作”来评论它。因为您在分配之前访问“customerNm”。

(您使用“customerNm+=...”,这意味着:创建一个新的字符串实例作为旧实例[尚未分配]和...的串联)。

这甚至不应该被编译。

我认为你的意思是:

customerNm += customerNm.EndsWith("s") ? "'" : "'s";

其中 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:

customerNm += customerNm.EndsWith("s") ? "'" : "'s";

where customerNm is a string already assigned to once before.

ペ泪落弦音 2024-08-10 02:42:17

不是您要问的问题,但您的代码似乎违反了 语法规则< /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.

违心° 2024-08-10 02:42:17
// Enforce English grammar
string customerNm = customerNm.EndsWith("s") ? customerNm+= "'" : customerNm+="'s"; 
// Enforce English grammar
string customerNm = customerNm.EndsWith("s") ? customerNm+= "'" : customerNm+="'s"; 
池木 2024-08-10 02:42:17

//Apply genitive case
string customerNm = customerNm.EndsWith("s") ? customerNm+= "'" : customerNm+="'s";

//Apply genitive case
string customerNm = customerNm.EndsWith("s") ? customerNm+= "'" : customerNm+="'s";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文