C# 4.0 的新“命名参数"不应该吗?特性被称为“命名参数"? [英] Shouldn't C# 4.0's new "named parameters" feature be called "named arguments"?

查看:24
本文介绍了C# 4.0 的新“命名参数"不应该吗?特性被称为“命名参数"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这种命名可能有历史原因,其他语言也有类似的特性,但在我看来,参数在 C# 中总是有一个名称.参数是未命名的.或者选择这个术语有什么特别的原因吗?

解决方案

是的,你是绝对正确的(无论如何,在我看来).具有讽刺意味的是,尽管我通常对这些术语很挑剔,但当我可能应该谈论参数传递"时,我仍然使用参数传递".我想有人可能会争辩说,在 C# 4.0 之前,如果您正在调用一个方法,您并不关心参数名称,而当您也可以在参数上指定它们时,名称将成为重要元数据的一部分.

我同意这会有所作为,而且术语很重要.

可选参数"绝对没问题 - 这是在您之前无法添加元数据时向参数添加元数据:)(话虽如此,就生成的 IL 而言,它不会是可选的...)

您希望我向团队征求反馈意见吗?

I suppose there could be historical reasons for this naming and that other languages have similar feature, but it also seems to me that parameters always had a name in C#. Arguments are the unnamed ones. Or is there a particular reason why this terminology was chosen?

解决方案

Yes, you're absolutely right (to my mind, anyway). Ironically, although I'm usually picky about these terms, I still use "parameter passing" when I should probably talk about "argument passing". I suppose one could argue that prior to C# 4.0, if you're calling a method you don't care about the parameter names, whereas the names become part of the significant metadata when you can specify them on the arguments as well.

I agree that it makes a difference, and that terminology is important.

"Optional parameters" is definitely okay though - that's adding metadata to the parameter when you couldn't do so before :) (Having said that, it's not going to be optional in terms of the generated IL...)

Would you like me to ask the team for their feedback?

这篇关于C# 4.0 的新“命名参数"不应该吗?特性被称为“命名参数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆