How to test if MethodInfo.ReturnType is type of System.Void?

Viewed 22537

Using reflection to obtain a MethodInfo, I want to test if the type returned is typeof System.Void.

Testing if it is System.Int32 works fine

 myMethodInfo.ReturnType == typeof(System.Int32)

but

 myMethodInfo.ReturnType == typeof(System.Void)

does not compile? At present Im testing if the string representation of the name is "System.Void" which seems very wrong.

3 Answers

Use

if(methodInfo.ReturnType.Name == "Void"){
  // Your Code.........
}
Related