命名参数混乱 [英] Named parameters confusion

查看:88
本文介绍了命名参数混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码中:(Web服务中的WebMethod属性)

In the following code: (WebMethod attribute in web service)

[WebMethod(CacheDuration = 300)]
public string GetData(string Id)
{

}

WebMethod属性类构造函数的智能感知将第二个重载显示为命名参数.我的疑问是,参数名称后没有使用冒号(:)指定的命名参数值.此处如何使用等于运算符?

The intellisense for the WebMethod attribute class constructor shows the second overload as named parameters. My doubt is that aren't named parameter values specified using a colon (:) after the parameter name. How come an equal to operator is used here ?

谢谢.

推荐答案

您正在使用属性特有的第三种语法,在该语法中,您可以在构造函数调用中使用Name = Value语法指定字段以对属性实例进行初始化

You're using a third syntax particular to attributes, in which you can specify fields to initialize on the attribute instance using a Name = Value syntax in the constructor call.

[WebMethod(cacheDuration: 300)]

也可以正常工作,但是它使用标准的命名参数语法而不是属性字段初始化语法.请记住,属性是在命名参数存在之前存在的.

would work just as well, but it's using standard named-parameter syntax instead of attribute field-initialization syntax. Remember that attributes were around before named parameters existed.

这篇关于命名参数混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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