Search code examples
c#arraysappendiformfile

When trying to append a FormFile to a FormFile[] (array) the FormFile is null


I have a FormFile[] that when I try adding a non-null FormFile object to it the array does not show any values.

     FormFile[] fileArray = new FormFile[10];
     FormFile myFile = new FormFile( /*Excel File*/ );
     fileArray.Append(myFile);

myFile[0] = null


Solution

  • If you are using System.Linq.Append this will return an new array with the value added at the end.
    If you do the following:

     FormFile[] fileArray = new FormFile[10];
     FormFile myFile = new FormFile( /*Excel File*/ );
     var newFileArray = fileArray.Append(myFile);
    

    newFileArray[11] will contain myFile