C# – Convert a List System.Object[] to List System.Int32[]

i'm new to C#,

I'm trying to use a function that as been created here

Actually i don't know how to return a list as array as a parameter. This function right here will use the "write" method of Odoo API.

    public void SetFieldValue(string field, object value)
    {
        var fieldAttribute = _fieldsResult.FirstOrDefault(f => f.FieldName == field);
        if (fieldAttribute == null) return;

        fieldAttribute.Changed = fieldAttribute.Changed == false;

        fieldAttribute.Value = value;
    }

So i did like this but it don't works :

  foreach (var result in results)
  {
       result.SetFieldValue("payment_method_ids", _NewPaymentLine.ToArray());
       result.Save();
  }

_NewPaymentLine is a List that i filled list this :

var _NewPaymentLine = new List<object>();
_NewPaymentLine.Add(new object[] { 4, Payment_Ids.GetField("id").Value });

All i can say its that the input value is a System.Object[] type and the output value is a System.Int32[] type.

Actually, what i return with the SetFieldValue is a System.Object[], but i think i have to return an System.Int32[], so the question is, how can i do to make my List of System.Object[] into System.Int32[]

Thanks in advance, i hope that someone can help me.



Read more here: https://stackoverflow.com/questions/68466206/c-sharp-convert-a-list-system-object-to-list-system-int32

Content Attribution

This content was originally published by Gabin at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: