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");
    }

解决方案 »

  1.   

    for   (int   i   =   0;   i   <   ss.Length;   i++)
    {                  
             fun010101(s[i]);               
     } 
      

  2.   

    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++) 
                  {                   
                       switch (ss[i])
                       {
                        case "01":
                            fun01();              
                            break;
                        case "010101":
                            fun010101();
                            break;
    ………………
                    }                        
                    } 
                    
            } 
      

  3.   

    用反射是可以的
    一点提示的
    type.InvokeMember(null,
                                              BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic |
                                              BindingFlags.Public, null, null, null);
      

  4.   

      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]==Mymethodinfob.Name){
      Mymethodinfob.Invoke(当前对象名称, null)
     }
      

  5.   


      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);
      }
      

  6.   

    string[] ss = new  string[4]{  "01 ",  "0101 ",  "010101 ",  "010102 "};
      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);
                   }
             }
      }
      

  7.   


    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 ");
        }
    }楼主这回明白了吗?
      

  8.   

    利用reflect的功能做,.net基本就是反射组成
      

  9.   


     MethodInfo[] m = type.GetMethods();
    type是什么
      

  10.   


     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);
                    }
                }
            }
      

  11.   

    反射基本上会比直接调用方法慢1000倍。为什么你不把方法直接作为参数传递呢?例如:Action[] ss = new Action[1] { fun010101, fun01, fun0101 };
    for (int i = 0; i < ss.Length; i++)
    {
        ss[i]();
      

  12.   

    Action[] ss = new Action[3] { fun010101, fun01, fun0101 };
    for (int i = 0; i < ss.Length; i++)
    {
        ss[i]();

      

  13.   

    我怎么看不到输出结果啊,
    我跟了一下,好像是没有进到if (Mymethodinfob.Name.Equals("fun" + ss[i]))
                    {
                        Mymethodinfob.Invoke(this, null);
                    }
    里面来
      

  14.   

    反射并不轻易拿出来,它总是在不得不使用的时候才使用的。如果你不得不使用反射来得到methodInfo,也应该尽可能把methodInfo转换为某一种delegate并缓存起来,以后就直接执行delegate。执行Invoke代价实在是巨大的。对于Action、Action<...>和Func<...>这三个delegate,尤其应该好好使用。