我複製和粘貼這個例子,它似乎失敗。爲什麼MethodBase爲空?爲什麼此反射中的MSDN示例失敗?
http://msdn.microsoft.com/en-us/library/system.reflection.parameterinfo.isout.aspx
編輯: 這裏是我的代碼的鏈接: http://img689.imageshack.us/img689/3453/94123952.png
讓我知道我的複製粘貼&是錯誤的。
這裏是爲那些再也無法查看圖像的代碼:
#region
using System;
using System.Reflection;
#endregion
namespace ConsoleApp
{
class parminfo
{
public static void mymethod(
int int1m, out string str2m, ref string str3m)
{
str2m = "in mymethod";
}
public static int Main(string[] args)
{
Console.WriteLine("\nReflection.Parameterinfo");
//Get the ParameterInfo parameter of a function.
//Get the type.
Type Mytype = Type.GetType("parminfo");
//Get and display the method.
MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
Console.Write("\nMymethodbase = " + Mymethodbase);
//Get the ParameterInfo array.
ParameterInfo[] Myarray = Mymethodbase.GetParameters();
//Get and display the IsOut of each parameter.
foreach (ParameterInfo Myparam in Myarray)
{
Console.Write("\nFor parameter # " + Myparam.Position
+ ", the IsOut is - " + Myparam.IsOut);
}
return 0;
}
}
}
發佈**您的**代碼。有時候人們會複製一些東西並改變一些東西,然後想知道爲什麼它不起作用。 – 2009-12-23 17:00:18
粘貼完整的代碼,就像你與你一樣。我想,這可能是由於方法案例名稱不匹配(您已經定義方法的方式以及使用反射時的方式)。 – shahkalpesh 2009-12-23 17:01:39