两类参数的区别'用法?

发布于 2024-11-29 08:15:00 字数 459 浏览 0 评论 0原文

我参与了一个项目(提前编写),该项目对我以前从未见过的参数有某种不同的用法。所以我想了解这两者之间有什么区别?

public string Login(string Email, string Password)
{
    Member member = MemberProvider.Instance.Login(Email: Email, Password: Password);
    // more implementation

}

vs

public string Login(string Email, string Password)
{
    Member member = MemberProvider.Instance.Login(Email, Password);
    // more implementation

}

提前致谢,

I have been gone into a project (written in advance) that has some kind of different usage for parameters that I have never seen before. So I wanted to learn what is the difference between these two ?

public string Login(string Email, string Password)
{
    Member member = MemberProvider.Instance.Login(Email: Email, Password: Password);
    // more implementation

}

vs

public string Login(string Email, string Password)
{
    Member member = MemberProvider.Instance.Login(Email, Password);
    // more implementation

}

Thanks in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

慕烟庭风 2024-12-06 08:15:00

第一种用法是使用命名参数,而第二种用法是使用普通的“将参数放在参数列表中的正确位置”用法。

前一种风格意味着您可以按照您喜欢的任何顺序放置参数,因此您不必记住(或关心)函数签名实际上具有它们的顺序。您将每个参数与参数名称相关联,并且该函数可以正确接收参数。

不过,两种风格的作用完全相同。前者是 C# 4 添加的便利功能。

The first usage is using named arguments, whereas the second is using the ordinary "put the argument in the correct spot in the parameter list" usage.

The former style means that you can put the arguments in any order you like, and so you don't have to remember (or care) what order the function signature actually has them. You associate each argument with a parameter name, and the function receives the arguments correctly.

Both styles do the exact same thing, though. The former is a convenience added with C# 4.

旧时模样 2024-12-06 08:15:00

功能上没什么。它们被命名为参数。

http://msdn.microsoft.com/en-us/library/dd264739.aspx

Functionly nothing. They're named parameters.

http://msdn.microsoft.com/en-us/library/dd264739.aspx

琉璃梦幻 2024-12-06 08:15:00

这些语句是等效的。第一条语句使用命名参数。从文档中:

命名参数使您能够为特定的参数指定参数
参数通过将参数与参数名称关联起来
与参数在参数列表中的位置相比。

The statements are equivalent. The first statement makes use of named parameters. From the documentation:

Named arguments enable you to specify an argument for a particular
parameter by associating the argument with the parameter's name rather
than with the parameter's position in the parameter list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文