两类参数的区别'用法?
我参与了一个项目(提前编写),该项目对我以前从未见过的参数有某种不同的用法。所以我想了解这两者之间有什么区别?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一种用法是使用命名参数,而第二种用法是使用普通的“将参数放在参数列表中的正确位置”用法。
前一种风格意味着您可以按照您喜欢的任何顺序放置参数,因此您不必记住(或关心)函数签名实际上具有它们的顺序。您将每个参数与参数名称相关联,并且该函数可以正确接收参数。
不过,两种风格的作用完全相同。前者是 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.
功能上没什么。它们被命名为参数。
http://msdn.microsoft.com/en-us/library/dd264739.aspx
Functionly nothing. They're named parameters.
http://msdn.microsoft.com/en-us/library/dd264739.aspx
这些语句是等效的。第一条语句使用命名参数。从文档中:
The statements are equivalent. The first statement makes use of named parameters. From the documentation: