Can I get the signature of a C# delegate by its type?
2,577
MethodInfo method = delegateType.GetMethod("Invoke");
Console.WriteLine(method.ReturnType.Name + " (ret)");
foreach (ParameterInfo param in method.GetParameters()) {
Console.WriteLine("{0} {1}", param.ParameterType.Name, param.Name);
}
Author by
qqqwww
Updated on June 23, 2022Comments
-
qqqwww almost 2 years
Python question:
print(sum(range(5),-1)) from numpy import * print(sum(range(5),-1)) 9 10
What is logical behind it? Thank you
-
Carcigenicate about 7 yearsNumpy must be redefining
range
, and it has different boundry rules. -
jkr about 7 yearsThe first line is equivalent to
0+1+2+3+4+(-1)
. The third line is equivalent to0+1+2+3+4
onaxis=-1
. Useimport numpy as np
and then rewrite the third line asnp.sum(range(5),-1)
. And read the documentation for np.sum() -
jkr about 7 yearsNumpy does not redefine
range
. The second argument innp.sum()
isaxis
. It will only sum the items in the first argument. -
Carcigenicate about 7 yearsAhh, my bad. Shot in the dark. I didn't think a summing function could have different behavior.
-
-
miradulo about 7 yearsIt's not so important, but
sum
doesn't add thestart
value at the end of the operation - it rather starts with thestart
value which defaults to 0, and adds the sequence to it. Like in CPython here.