I'm trying to get the MethodInfo of a static method in a static class. When running the following line, I only get the basic 4 methods, ToString, Equals, GetHashCode and GetType:
MethodInfo[] methodInfos = typeof(Program).GetMethods();
How can I get the other methods that are implemented in this class?
Static methods take all the data from parameters and compute something from those parameters, with no reference to variables. We can inherit static methods in Java.
A static method can only use and call other static methods or static data members. It is usually used to operate on input arguments (which can always accept), perform calculation and return value.
Static data and static methods do not take up memory in individual instances.
Try this way:
MethodInfo[] methodInfos = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.Public);
var methods = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With