There is a Dereviative class in which I want to make an array length check, which is a function argument. Delegate Announcement in Dereviative Class:

public delegate double functionToDereviate(double[] x); 

Then I want to use this delegate as an argument to the static function of the Dereviative class:

  public static double takeDereviative( functionToDereviate func, double[] argumentForFunc, int argumentForDereviation, double step) 

and in this method I want to check the length of the array x

I'm stuck on this:

 func.Method.GetParameters()[0].ParameterType. 

And where to dig further?



    1 answer 1

    Check the length of the array w - w.Length .

    For your delegate of arguments, there can be an array of any length, so the question “how long the array takes the delegate” is meaningless.

    In C #, there is no separate type, for example, "an array of 5 elements of type int ", there is only the type "array of elements of type int ". The number of elements is the run-time property of an array object (which can be interrogated using the above-mentioned Length property.)

    • Is there no method to get the length of such an array during program execution? - Demonoid67
    • one
      @ Demonoid67: What array? Which is actually transmitted or which can be transmitted? Why Length not suitable? - VladD
    • clear =) Thank you! - Demonoid67
    • four
      Hmm ... just realized the absurdity of your question! - Demonoid67
    • one
      @ Demonoid67: please! Well, that sorted out. - VladD