Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.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# 在运行时更改数组的名称_C# - Fatal编程技术网

C# 在运行时更改数组的名称

C# 在运行时更改数组的名称,c#,C#,在我的场景中,我从一个web表中获取所有数据并将其存储在一个数组中。每个数组保存一行数据 我这里的问题是,我想为每个迭代创建一个具有新名称的新数组。因此,第一行中的数据存储在一个数组中。获取第二行数据时,应创建一个新数组,并且数据必须存储在新创建的数组中 我用的是c语言 这是我的密码 IWebElement table = _Browser.FindElementById("", "gview_jqGrid"); IList<IWebElement>

在我的场景中,我从一个web表中获取所有数据并将其存储在一个数组中。每个数组保存一行数据

我这里的问题是,我想为每个迭代创建一个具有新名称的新数组。因此,第一行中的数据存储在一个数组中。获取第二行数据时,应创建一个新数组,并且数据必须存储在新创建的数组中

我用的是c语言

这是我的密码

        IWebElement table = _Browser.FindElementById("", "gview_jqGrid");
        IList<IWebElement> rowCollections = table.FindElements(By.TagName("tr"));
        int RowCnt = rowCollections.Count;
        String[] DataArray = new String[RowCnt];
        foreach (IWebElement row in rowCollections)
        {

               IList<IWebElement> colCollection = row.FindElements(By.TagName("td"));
                foreach (IWebElement col in colCollection)
                {
                    String Data = col.Text;
                    // ------ Here I want a array to store data. A new array for each Iteration
                    j++;
                }
          }
IWebElement表=_Browser.FindElementById(“,“gview_jqGrid”);
IList rowCollections=table.FindElements(按.TagName(“tr”));
int RowCnt=rowCollections.Count;
字符串[]数据数组=新字符串[RowCnt];
foreach(行集合中的IWebElement行)
{
IList colcolcollection=row.FindElements(按.TagName(“td”));
foreach(colCollection中的IWebElement列)
{
字符串数据=列文本;
//------这里我需要一个数组来存储数据。每次迭代都需要一个新数组
j++;
}
}

如果您知道行是什么,只需创建一个包含行数据的类,然后创建一个类,并在每次检索行时将其推入数组中

我认为您需要使用不同的数据结构,如2D数组或哈希表/字典

假设您有一个数组列表:

List<int[]> arrayList = new List<int[]>();
然后您可以将这些数组放入列表中

arrayList.Add(intArray);

您应该使用多维数组。数组声明如下所示:

object[,] table = new object[10, 10];
见:

如果您不知道它会变得多大,那么您可能需要一个数组列表。假设有10列:

List<object[]> table = new List<object[]>();
var row = new object[10];
// populate row array here...
table.Add(row);
List table=新列表();
变量行=新对象[10];
//在此处填充行数组。。。
表.添加(行);

如果您确实想为数组命名,请使用字典:

var arrays = new Dictionary<string, int[]>();

while (rows available) {
    var a = new int[10];
    FillArrayFromRow(a, row);
    string name = GetNameFrom(row);
    arrays.Add(name, a);
}

我没有看到任何代码。也许你想看看?你说的新名字是什么意思?我想你需要的是一个数组数组,也就是2d数组。你可以使用2d数组吗?你不能动态地更改数组的名称,但是你可以将数据分配给一个新的内存区域,这个区域具有相同的效果。因此,
myarray[0][]
是第一次迭代中的一个,第二次迭代中的
myarray[1][]
等等。我仍然强烈认为他应该使用一个数据类,每个数据类包含一行
var arrays = new Dictionary<string, int[]>();

while (rows available) {
    var a = new int[10];
    FillArrayFromRow(a, row);
    string name = GetNameFrom(row);
    arrays.Add(name, a);
}
int[] x = arrays["a name"];