C#反射相關資料

  1. 利用反射將字符串轉換爲類類型和方法

    說明: voidname: 指方法的字符串名稱.
     
    Type type = System.Type.GetType("AllenExcelImport.DAL.CostRecImport");      //得到類類型,類必須全路徑
    Object obj = Activator.CreateInstance(type);                                 //得到命名空間名
    MethodInfo methodinfo = type.GetMethod(voidname);                           //得到方法
    string msg = (string)methodinfo.Invoke(obj, new object[] { lstT,Convert.ToInt32(txtfyear.Text.Trim()) });

     

 

 

 

 

參考:https://blog.csdn.net/weixin_30300225/article/details/97726971

發佈了3 篇原創文章 · 獲贊 6 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章