Search code examples
c#performancelinqsaprfc

Using LINQ to convert array object[,] to array


I have information from external system that always return to me in the following format:

SAP data

I am required to convert this information from object[,] to an Array split on "|". I'm been using LINQ in VB to get this information:

Dim vSAPdataTemp(,) As Object = Local_SAPtableData.Data

Dim vLinq = From TempResult In vSAPdataTemp
            Select Value = Array.ConvertAll(TempResult.ToString.Split(RFC_DelimiterChar),
                                    Function(vVal) CObj(vVal.ToString.Trim))

Dim vNewSAPdata() As Object = vLinq.ToArray

But now I'm moving to C# and I'm stuck with the following error:

LINQ ERROR

When using this code:

var vSAPdataTemp = Local_SAPtableData.Data;

Local_SAPtableData.FreeTable();
fw.gcCleaner();
Local_SAPtableData = null;

var vLinq = (from TempResult in (vSAPdataTemp as Object[,])
                       select string strValue = Array.ConvertAll(TempResult.Split(stcVariables.strSapRfcDelimiterChar), 
                           vVal => (vVal as object).ToString().Trim()));

var vNewSAPdata = vLinq.ToArray<string>();

What (if any) workaround exists for this issue?


Solution

  • Thanks to @MarcinJuraszek for the answer to my problem. I only want to post the resolution of my specific case:

    var vSAPdataTemp = Local_SAPtableData.Data;
    
    string[][] vLinq = (vSAPdataTemp as Object[,]).Cast<string>()
                    .Select(str => str.Split(stcVariables.strSapRfcDelimiterChar)
                    .Select(stra => stra.Trim()).ToArray()).ToArray();
    

    Result