为什么C#can';t传递数组参数?

为什么C#can';t传递数组参数?,c#,arrays,C#,Arrays,当我使用DataRow数组参数编写函数时,它会提示“)使用行专用字典getViewColumnHeaderName(DataRow DR[]),这是我的代码: private Dictionary<int,string> getViewColumnHeaderName(DataRow DR[]) { System.Collections.Generic.Dictionary<int, string> dic=new System.Collections.Generi

当我使用DataRow数组参数编写函数时,它会提示“)使用行
专用字典getViewColumnHeaderName(DataRow DR[]),这是我的代码:

private Dictionary<int,string> getViewColumnHeaderName(DataRow DR[])
{
  System.Collections.Generic.Dictionary<int, string>  dic=new System.Collections.Generic.Dictionary<int, string> ();
  for(int i=0;i<DR[0].Table.Columns.Count;i++)
  {
    dic.Add(i,DR[0].Table.Columns[i].ColumnName.ToString());
  }
  return dic;
}
专用字典getViewColumnHeaderName(DataRow DR[])
{
System.Collections.Generic.Dictionary dic=新的System.Collections.Generic.Dictionary();

对于(int i=0;i将
DataRow DR[]
更改为
DataRow[]DR

private Dictionary<int,string> getViewColumnHeaderName(DataRow[] DR)

在参数类型(而非参数名称)旁边添加
[]

private Dictionary<int,string> getViewColumnHeaderName(DataRow[] DR)
私有字典getViewColumnHeaderName(DataRow[]DR)

如前所述,您应该将
[]
添加到参数类型,而不是参数名称

这可能看起来有点违反直觉,因为您将使用
DR[i]
引用该数组中的项。但是,在方法签名中,您定义的是将通过参数传递的内容,而不是特定对象本身。正在传递的项是
DataRow
的数组,而不是
DR
的数组

private Dictionary<int,string> getViewColumnHeaderName(DataRow[] DR)