使用它作为二维数组中的搜索来迭代列表

时间:2018-03-19 21:28:26

标签: c# list unity3d

我有需要翻译成多维数组的列表。然后我想在列表中的值中搜索其他几个多维数组,并将它们放入包含所有数据的新多维数组中。这些数组的结构如下,并且是锯齿状数组。

userArray = [StudentID, Password, Username, TutorGroup, YearGroup, AccountType]
MeetRequests = [StudentID, Request, Urgent]
feelingsArray = [StudentID, Tiredness, Workload, Stress]

我要求每个列表中的所有值,除了来自userArray的用户名和密码以及来自MeetRequests和feelingsArray的StudentID。 我之前提到的列表包含所有StudentID。我想迭代列表然后在上面的三个数组中搜索相应的StudentArray。但是,我收到以下代码的错误:

    //Defines all the stuff
        private Rect windowRect = new Rect(0, 0, Screen.width, Screen.height);
public Vector2 scrollPosition = Vector2.zero;
private int BSpace;
public string[,] SortedStudentArray;
private int j;
private string[][] MeetRequests;
private string[] temp;
private System.Collections.Generic.List<string> H_Priority = new List<string>();
private System.Collections.Generic.List<string> M_Priority = new List<string>();
private System.Collections.Generic.List<string> L_Priority = new List<string>();
private System.Collections.Generic.List<string> FullList = new List<string>();
private string[] Holding = new string[5];
private string[] SearchTerms;

    //This is where the main body of code is

        string[][] feelingsArray = GetComponent<Userdata>().CallFeelings();

    //Info array about each user
    string[,] SortedStudentArray = new string[FullList.Count, 11];


    //for each item in FullList
    for (int y = 0; y < FullList.Count; y++)
    {
        //Find corresponding Student Info in userArray
        Holding = Array.BinarySearch(Userdata.userArray, FullList<y>);
        Array.Copy(Holding, 0, SortedStudentArray[y], 0, 5);
        Holding = Array.BinarySearch(MeetRequests, FullList<y>);
        Array.Copy(Holding, 1, SortedStudentArray[y], 6, 2);
        Holding = Array.BinarySearch(feelingsArray, FullList<y>);
        Array.Copy(Holding, 1, SortedStudentArray[y], 8, 3);
    }

    return SortedStudentArray;

所以,如果我可以给出一些如何搜索其他数组的方向,那么我将不胜感激。就我所知,Array.Copy不适用于多维数组,并且List也存在类型错误

我得到的错误是:

Assets/Scripts/Staff/MeetingRequestViewer.cs(144,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Assets/Scripts/Staff/MeetingRequestViewer.cs(166,29): error CS0029: Cannot implicitly convert type `int' to `string[]'
Assets/Scripts/Staff/MeetingRequestViewer.cs(168,29): error CS0029: Cannot implicitly convert type `int' to `string[]'
Assets/Scripts/Staff/MeetingRequestViewer.cs(170,29): error CS0029: Cannot implicitly convert type `int' to `string[]'
Assets/Scripts/Staff/MeetingRequestViewer.cs(20,70): error CS0104: `List' is an ambiguous reference between `Boo.Lang.List<T>' and `System.Collections.Generic.List<T>'
Assets/Scripts/Staff/MeetingRequestViewer.cs(20,66): error CS0029: Cannot implicitly convert type `Boo.Lang.List<string>' to `System.Collections.Generic.List<string>'
Assets/Scripts/Staff/MeetingRequestViewer.cs(21,70): error CS0104: `List' is an ambiguous reference between `Boo.Lang.List<T>' and `System.Collections.Generic.List<T>'
Assets/Scripts/Staff/MeetingRequestViewer.cs(21,66): error CS0029: Cannot implicitly convert type `Boo.Lang.List<string>' to `System.Collections.Generic.List<string>'
Assets/Scripts/Staff/MeetingRequestViewer.cs(22,70): error CS0104: `List' is an ambiguous reference between `Boo.Lang.List<T>' and `System.Collections.Generic.List<T>'
Assets/Scripts/Staff/MeetingRequestViewer.cs(22,66): error CS0029: Cannot implicitly convert type `Boo.Lang.List<string>' to `System.Collections.Generic.List<string>'
Assets/Scripts/Staff/MeetingRequestViewer.cs(23,68): error CS0104: `List' is an ambiguous reference between `Boo.Lang.List<T>' and `System.Collections.Generic.List<T>'

Assets / Scripts / Staff / MeetingRequestViewer.cs(23,64):错误CS0029:无法隐式转换类型Boo.Lang.List<string>' to System.Collections.Generic.List'

1 个答案:

答案 0 :(得分:0)

为了解决我的问题,我使用了一个foreach循环,它允许我遍历FullList,然后将变量与userData.userArray[y][0]中的元素进行比较。传输我使用嵌套for循环的数据循环遍历userData.userArray中的元素并将它们转移到SortedStudentArray

 string[,] SortedStudentArray = new string[FullList.Count, 11];

    //Line Counter
    int SSAPos = 0;

    // For every element in FullList
    foreach (var item in FullList)
    {
        //For each user in userArray
        for (int y = 0; y < Userdata.userArray.Length; y++)
        {
            if (Userdata.userArray[y][0] == item)
            {
                for (int n = 0; n < Userdata.userArray[y].Length; n++)
                {
                    SortedStudentArray[SSAPos, n] = Userdata.userArray[y][n];
                }
                SSAPos +=1; 
                break;
            }
        }