Function that Creates the Default of an Array

  • Thread starter Thread starter zequion1
  • Start date Start date
Z

zequion1

Guest
I am doing a function that returns the default of any type of variable, but I have a problem with arrays.
In the following function, I indicate "dynamic Origin" and I can specify the number of dimensions "dynamic lengths_dyn". But if "lengths_dyn" is = null, I don't want it to create any number of dimensions.
When 0 is the minimum, it returns System.DateTime[0][] when the default is System.DateTime[].



public static System.Array Fcn_CreateInstance_Array(dynamic Origen, dynamic lengths_dyn = null)
{ System.Array MyArray_Retorno = null;

System.Type Origen_Type = Origen.GetType(); // {Name = "DateTime[]" FullName = "System.DateTime[]"}

if (lengths_dyn == null) lengths = 0;

MyArray_Retorno = System.Array.CreateInstance(Origen_Type, lengths); // {System.DateTime[0][]} BAD, Y NEED System.DateTime[].

return MyArray_Retorno;
}

Continue reading...
 
Back
Top