MethodInfo.ReturnType Property
.NET Framework 4
Gets the return type of this method.
Assembly: mscorlib (in mscorlib.dll)
The following example displays the return type of the specified method.
using System; using System.Reflection; class Mymethodinfo { public static int Main() { Console.WriteLine ("\nReflection.MethodInfo"); // Get the Type and MethodInfo. Type MyType = Type.GetType("System.Reflection.FieldInfo"); MethodInfo Mymethodinfo = MyType.GetMethod("GetValue"); Console.Write ("\n" + MyType.FullName + "." + Mymethodinfo.Name); // Get and display the ReturnType. Console.Write ("\nReturnType = {0}", Mymethodinfo.ReturnType); return 0; } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Void return type checking syntax
MethodInfo mi = MyType.GetMethod("MyFunction");
if(mi.ReturnType != typeof(void)){
//do something
}
if(mi.ReturnType != typeof(void)){
//do something
}
- 2/14/2011
- alokegupta
Example of void funtion would be usefull
There is no information how to test for void functions aka. Subs in VB. Testing for void functions is one of the most common tasks associated with this property. However it is not clear to everyone that a type System.void exists (and it looks like that it exits solely for this property).
Searching the web for a solution to this problem, I also found that people don't how to correctly test for this type.
I suggest to include in the sample code how to test for void functions.
Searching the web for a solution to this problem, I also found that people don't how to correctly test for this type.
I suggest to include in the sample code how to test for void functions.
- 9/28/2010
- Rainerschw