Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 这个表达式a[b]在C中代表什么#_C# - Fatal编程技术网

C# 这个表达式a[b]在C中代表什么#

C# 这个表达式a[b]在C中代表什么#,c#,C#,我经常在维护代码中看到这个表达式 Global["Name"] 这代表什么?我使用过Global.Name,但从未使用过Global[“Name”] 是否有一个地方使用这种类型的表达式?这称为。在这种情况下,Global可能是某种字典或哈希表“名称”是访问该词典中特定项的键它用于查找包含键/值对的词典和集合,例如 var peopleAges = new System.Collections.Generic.Dictionary<string, int>(); peopleAges

我经常在维护代码中看到这个表达式

Global["Name"]
这代表什么?我使用过
Global.Name
,但从未使用过
Global[“Name”]


是否有一个地方使用这种类型的表达式?

这称为。在这种情况下,
Global
可能是某种字典或哈希表<代码>“名称”是访问该词典中特定项的键

它用于查找包含键/值对的词典和集合,例如

var peopleAges = new System.Collections.Generic.Dictionary<string, int>();
peopleAges["fred"] = 21;
peopleAges["emma"] = 18;

var fredAge = peopleAges["fred"];  // returns 21
var peopleAges=new System.Collections.Generic.Dictionary();
人口[“弗雷德”]=21;
人口[“emma”]=18;
var fredAge=peopleAges[“fred”];//返回21

这是C允许的一种缩写形式,称为默认属性。当类具有DefaultMemberAttribute集时,C允许以这种方式忽略该属性中命名的属性的名称。

否。它仅适用于索引器,即使将属性定义为默认成员,也不能忽略该属性。“如果属性具有参数,并且属性或其某个访问器的名称与DefaultMemberAttribute指定的名称匹配,则该属性将作为索引器(Visual Basic中的默认索引属性)导入。”C#透明地执行此操作,以便不必定义属性。我称之为默认属性,因为我在很久以前使用过VB.NET。