[英]asp.net Syntax [] instead of ()
有人可以解释一下为什么在下面的单行代码(ASP.NET后面的C#代码)中使用括号而不是(),并提供此语法的技术文档参考吗?
string cssFile = Request.Cookies["InquiryId"].Value;
You may take a look at indexed properties . 您可以看一下索引属性 。 That's what is defined for the Cookies property. 这就是为Cookies属性定义的内容。
您正在查看的[]
语法称为索引器 (msdn链接)。
它的ac#而不是用于访问数组的VB.Net约定,实际上与asp.net无关,而是背后代码的语言选择
Because Cookies is some kind of dictionary. 因为Cookies是某种字典。 Or more general: It defines an indexer property. 或更笼统:它定义索引器属性。 Therefor the [] have to be used. 因此必须使用[]。 () are used for a method call, which is just something different. ()用于方法调用,这只是有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.