从Api

时间:2016-01-05 18:23:56

标签: c# arrays multidimensional-array acumatica jagged-arrays

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

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

其次我想按开始日期排序,即[X] [4]

我已经尝试了几次搜索,看到了下面我累了

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

但我真的不明白它是如何运作的,所以不能让它发挥作用......

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

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

#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
            );

1 个答案:

答案 0 :(得分:1)

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

// 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();