从 Api 排序多个 Dimensional/Jagged 数组

Sort Multi Dimensional/Jagged Array from Api

除了目前在堆栈上找到的内容之外,我还需要一些帮助。

我有一个看起来像这样的数组(首先是多维的还是锯齿状的?)

其次,我想按 [X][4]

开始日期排序

我尝试了几次搜索,看到了下面我厌倦的

//string[][] SenorityList = SalesEmployees.OrderBy(inner => inner[0][4]).ToArray();

但我真的不明白它是如何工作的所以不能让它工作...

我还看到了 http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=151,看起来它可以通过使用 class 来工作,但我还是不理解它,所以不确定如何根据我的需要部署它。

下面我添加了我正在使用的构建数组的导出,因此您可以看到变量名称等。

#region GrabSalesEmployees
        DateTime Now = DateTime.Now;
        EP203000Content EP203000 = context.EP203000GetSchema();
        context.EP203000Clear();
        string[][] SalesEmployees;
        SalesEmployees = context.EP203000Export(
                new Command[] {
                    EP203000.EmployeeInfo.ServiceCommands.EveryEmployeeID,
                    EP203000.GeneralInfoEmployeeSettings.EmployeeClass,
                    EP203000.EmployeeInfo.Status,
                    EP203000.EmployeeInfo.EmployeeID,
                    EP203000.EmploymentHistory.Position,
                    EP203000.EmploymentHistory.StartDate,
                    EP203000.EmploymentHistory.EndDate
                },

                new Filter[] {
                    new Filter { Field = new Field { FieldName = EP203000.GeneralInfoEmployeeSettings.EmployeeClass.FieldName }, Condition = FilterCondition.Equals, Value = "SALES", Operator = FilterOperator.And },             
                    new Filter { Field = new Field { FieldName = EP203000.EmployeeInfo.Status.FieldName }, Condition = FilterCondition.Equals, Value = "Active", Operator = FilterOperator.And },                                     
                    new Filter { Field = new Field { FieldName = EP203000.EmployeeInfo.EmployeeID.FieldName }, Condition = FilterCondition.NotEqual, Value = "BA00000450", Operator = FilterOperator.And },
                },

                    0, false, false
            );

锯齿状数组是 array of arrays。如果您确定每个内部数组的第四个元素中都包含日期,您可以使用下一个代码:

// for each element of external array (1st dimension) order by 4th element of jagged (2nd dimension) by ascending
string[][] SenorityList = SalesEmployees.OrderBy(innerArray => innerArray[4]).ToArray();

当然更好的方法是检查元素并将它们转换为 DateTime:

string[][] SenorityList = SalesEmployees.OrderBy(innerArray =>
        {
            if (innerArray.Length >= 5)
            {
                DateTime startDate;
                if (DateTime.TryParse(innerArray[4], out startDate))
                    return startDate;
            }
            // if you want that unpasrsed dates will be on the end of the list use DateTime.MaxValue
            return DateTime.MaxValue;
        }).ToArray();