【发布时间】:2022-07-18 21:15:04
【问题描述】:
我在这个microsoft page上阅读了以下代码
Type t = typeof(String);
MethodInfo substr = t.GetMethod("Substring",
new Type[] { typeof(int), typeof(int) });
Object result =
substr.Invoke("Hello, World!", new Object[] { 7, 5 });
Console.WriteLine("{0} returned \"{1}\".", substr, result);
问题是 MethodInfo 类中没有 Invoke(String,Object[]) 方法。 (t.GetMethod 返回一个 MethodInfo 对象对吧?)
还有另一个问题:有时我看到 Object(class/datatype) 变量被声明为对象,有时被声明为 Object。有什么区别吗?
【问题讨论】:
-
最后一个问题的答案:Built-in types
-
它有一个从
MethodBase继承的Invoke(object, object[])方法。
标签: c#