protected void Button1_Click(object sender, EventArgs e)
{
string[] ss = new string[4] { "01", "0101", "010101", "010102" };
for (int i = 0; i < ss.Length; i++)
{
//我如何调用fun010101()方法 , 用fun加前缀,后面的数字用SS数组合成
}
} private void fun010101()
{
Response.Write("111");
} private void fun010102()
{
Response.Write("111");
}
{
string[] ss = new string[4] { "01", "0101", "010101", "010102" };
for (int i = 0; i < ss.Length; i++)
{
//我如何调用fun010101()方法 , 用fun加前缀,后面的数字用SS数组合成
}
} private void fun010101()
{
Response.Write("111");
} private void fun010102()
{
Response.Write("111");
}
{
fun010101(s[i]);
}
{
string[] ss = new string[4] { "01 ", "0101 ", "010101 ", "010102 " };
for (int i = 0; i < ss.Length; i++)
{
switch (ss[i])
{
case "01":
fun01();
break;
case "010101":
fun010101();
break;
………………
}
}
}
一点提示的
type.InvokeMember(null,
BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic |
BindingFlags.Public, null, null, null);
MethodInfo[] m= type.GetMethods();
for (int i = 0; i < ss.Length; i++)
{
MethodInfo Mymethodinfob = mtype.GetMethod(m[i]);
if(fun+ss[i]==Mymethodinfob.Name){
Mymethodinfob.Invoke(当前对象名称, null)
}
string[] ss = new string[4]{ "01 ", "0101 ", "010101 ", "010102 "};
Type mtype=typeof(当前对象名称);
MethodInfo[] m= type.GetMethods();
for (int i = 0; i < ss.Length; i++)
{
MethodInfo Mymethodinfob = mtype.GetMethod(m[i]);
if("fun"+ss[i].Equals(Mymethodinfob.Name)){
Mymethodinfob.Invoke(当前对象名称, null);
}
Type mtype=typeof(当前对象名称);
MethodInfo[] m= type.GetMethods();
for (int i = 0; i < ss.Length; i++)
{
for (int j = 0; j < m.Length; j++)
{
MethodInfo Mymethodinfob = mtype.GetMethod(m[j]);
if("fun"+ss[i].Equals(Mymethodinfob.Name))
{
Mymethodinfob.Invoke(this, null);
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Reflection;public partial class MyStudent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void add_Click(object sender, EventArgs e)
{
string[] ss = new string[4] { "01 ", "0101 ", "010101 ", "010102 " };
Type mtype = typeof(MyStudent);
MethodInfo[] m = type.GetMethods();
for (int i = 0; i < ss.Length; i++)
{
for (int j = 0; j < m.Length; j++)
{
MethodInfo Mymethodinfob = mtype.GetMethod(m[j]);
if ("fun" + ss[i].Equals(Mymethodinfob.Name))
{
Mymethodinfob.Invoke(this, null);
}
}
} }
private void fun010101()
{
Response.Write("1dddd ");
} private void fun010102()
{
Response.Write("111 ");
}
}楼主这回明白了吗?
MethodInfo[] m = type.GetMethods();
type是什么
string[] ss = new string[4] { "01 ", "0101 ", "010101 ", "010102 " };
Type mtype = typeof(MyStudent);
MethodInfo[] m = mtype.GetMethods();
for (int i = 0; i < ss.Length; i++)
{
for (int j = 0; j < m.Length; j++)
{
MethodInfo Mymethodinfob = m[j] as MethodInfo; ;
if (Mymethodinfob.Name.Equals("fun" + ss[i]))
{
Mymethodinfob.Invoke(this, null);
}
}
}
for (int i = 0; i < ss.Length; i++)
{
ss[i]();
}
for (int i = 0; i < ss.Length; i++)
{
ss[i]();
}
我跟了一下,好像是没有进到if (Mymethodinfob.Name.Equals("fun" + ss[i]))
{
Mymethodinfob.Invoke(this, null);
}
里面来