c# 反射实例

上传者: jianwangwuwo5 | 上传时间: 2023-09-14 06:06:16 | 文件大小: 21KB | 文件类型: RAR
//c# 反射实例 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; namespace ConsoleApplication1 { class Program { static void Main( string[] args ) { // 类型名,方法名,参数 string className = "ConsoleApplication1.A"; string methodName = "Fun"; string param = "param"; // 获取程序集 Assembly assembly = Assembly.GetExecutingAssembly(); // 取得类型,方法;定义参数 Type type = assembly.GetType(className); MethodInfo method = type.GetMethod(methodName); object[] parameters = new object[] { param }; // 创建实例;调用方法(传递参数,获取返回值) object instance = assembly.CreateInstance(type.ToString()); string rt = (string)method.Invoke(instance, parameters); // 打印输出 Console.WriteLine(rt); Console.ReadKey(); } } class A { public string Fun(string param) { return "A.Fun:" + param; } } }

文件下载

资源详情

[{"title":"( 14 个子文件 21KB ) c# 反射实例","children":[{"title":"Reflection","children":[{"title":"bin","children":[{"title":"Debug","children":[{"title":"ConsoleApplication1.exe <span style='color:#111;'> 5.00KB </span>","children":null,"spread":false},{"title":"ConsoleApplication1.pdb <span style='color:#111;'> 13.50KB </span>","children":null,"spread":false},{"title":"ConsoleApplication1.vshost.exe <span style='color:#111;'> 11.33KB </span>","children":null,"spread":false},{"title":"ConsoleApplication1.vshost.exe.manifest <span style='color:#111;'> 490B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Program.cs <span style='color:#111;'> 1.07KB </span>","children":null,"spread":false},{"title":"obj","children":[{"title":"x86","children":[{"title":"Debug","children":[{"title":"ConsoleApplication1.exe <span style='color:#111;'> 5.00KB </span>","children":null,"spread":false},{"title":"ConsoleApplication1.pdb <span style='color:#111;'> 13.50KB </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferencesInput.cache <span style='color:#111;'> 5.64KB </span>","children":null,"spread":false},{"title":"TempPE","children":null,"spread":false},{"title":"ConsoleApplication1.csproj.FileListAbsolute.txt <span style='color:#111;'> 555B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true},{"title":"Solution1.sln <span style='color:#111;'> 879B </span>","children":null,"spread":false},{"title":"Solution1.suo <span style='color:#111;'> 15.00KB </span>","children":null,"spread":false},{"title":"ConsoleApplication1.csproj <span style='color:#111;'> 2.40KB </span>","children":null,"spread":false},{"title":"Program.cs.orig <span style='color:#111;'> 235B </span>","children":null,"spread":false},{"title":"Properties","children":[{"title":"AssemblyInfo.cs <span style='color:#111;'> 1.43KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明