</pre>某些地方需要用到泛型 或者不知道类型的地方 就用如下方法:<pre code_snippet_id="1963345" snippet_file_name="blog_20161102_1_2202380" name="code" class="cpp">public static dictionary<object,int> allobj=new dictionary<object,int>();
public static void save<T>(T t) where T:Mnnobehaver
{
allobj[t]=1;//把T类型存为object类型
}
public void Notify()
{
foreach(KeyValuePair<object,int> kv in allobj)
{
System.Type tp=kv.Key.GetType();//获得的就是脚本类型如commonmemory
System.Reflection.MethodInfo method=tp.GetMethod("Start");//获取该脚本的Start方法
if(method!=null)
{
method.Invoke(kv.Key,new object[]{1,“1”,1, 1});//第二个参数对应Start的几个参数。必须传正确类型。数组代表参数数量、
method.Invoke(null,new object[]{1,1,1, 1});//静态方法 第一个参数传null。普通方法传其实例。
}
}
}