Csharp/C#教程:如何使用reflection调用ref / out参数的方法分享


如何使用reflection调用ref / out参数的方法

想象一下,我有以下课程:

class Cow { public static bool TryParse(string s, out Cow cow) { ... } } 

是否可以通过reflection调用TryParse ? 我知道基础知识:

 var type = typeof(Cow); var tryParse = type.GetMethod("TryParse"); var toParse = "..."; var result = (bool)tryParse.Invoke(null, /* what are the args? */); 

你可以这样做:

上述就是C#学习教程:如何使用reflection调用ref / out参数的方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 static void Main(string[] args) { var method = typeof (Cow).GetMethod("TryParse"); var cow = new Cow(); var inputParams = new object[] {"cow string", cow}; method.Invoke(null, inputParams); } class Cow { public static bool TryParse(string s, out Cow cow) { cow = null; Console.WriteLine("TryParse is called!"); return false; } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1019202.html

(0)
上一篇 2022年1月4日
下一篇 2022年1月4日

精彩推荐