Warning: file_exists(): open_basedir restriction in effect. File(/www/wwwroot/www.shawanolakecottagemartzke-cmy/wp-content/plugins/imwpcache-dist//bootstrap/index.php) is not within the allowed path(s): (/www/wwwroot/www.shawanolakecottagemartzke.com-root/:/tmp/) in /www/wwwroot/www.shawanolakecottagemartzke.com-root/index.php on line 1
C# 使用反射调用方法_MethodInfo.Invoke方法-沙沙资源网
沙沙资源网 IT教程 C# 使用反射调用方法_MethodInfo.Invoke方法

C# 使用反射调用方法_MethodInfo.Invoke方法

methodinfo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Reflection;

namespace B002_使用反射调用方法_MethodInfo.Invoke方法_
{
    class Myclass
    {
          public  int a;
          public int b;
          public Myclass(int x, int y)
        {
            a = x;
            b = y;
        }
          public int Sum()
        {
            return a + b;
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
          
            //Ordinal 使用序号排序规则比较字符串。 比较严格和准确的,并且在性能上也很好
             Myclass mc = new Myclass(5, 10);//初始化值
             int mysum = mc.Sum();
             //Console.WriteLine("sum is " + mysum);
            Type ty = typeof(Myclass);
            int val;
            MethodInfo[] m = ty.GetMethods();
            foreach (MethodInfo m1 in m)
            {
                if (m1.Name.Equals("Sum", StringComparison.Ordinal))
                {
                   
                    val = (int)m1.Invoke(mc, null);//反射:方法调用类。借助;
                    Console.WriteLine("sum is " + val);
                }
            } 
            Console.ReadLine();
        }
    }
}


//StringComparison字符串比较枚举类型
//CurrentCulture 使用区域敏感排序规则和当前区域比较字符串。 
//CurrentCultureIgnoreCase 使用区域敏感排序规则、当前区域来比较字符串,同时忽略被比较字符串的大小写。 
//InvariantCulture 使用区域敏感排序规则和固定区域比较字符串。 
//InvariantCultureIgnoreCase 使用区域敏感排序规则、固定区域来比较字符串,同时忽略被比较字符串的大小写。 
//Ordinal 使用序号排序规则比较字符串。 比较严格和准确的,并且在性能上也很好
//OrdinalIgnoreCase 使用序号排序规则并忽略被比较字符串的大小写,对字符串进行比较。

支付宝生活圈怎么私信 支付宝生活圈私信方法

大家都知道,支付宝生活圈其是个类似朋友圈的社交功能,该功能是经常使用支付宝的伙伴们也不知道吧!在生活圈中伙伴们可观看好友们近

小编告诉你ps图章工具怎么使用

ps是一款非常知名的图片处理软件,在ps中有很多ps工具,但是很多朋友不知道怎么使用ps工具,为了让大家能够更好的使用ps,今天小编就来说

vagaa 哇嘎不能搜索资源解决方法(图解)

本文为大家具体的介绍vagaa哇嘎搜索没反应,无法搜索的解决方法,希望可以帮助的大家。推荐下载:1、下载安装最新版Vagaa客户端; 2、如

linux通过curl方式调用接口

今天遇到个需求,linux上将txt文件导入数据库,需要监测txt中的数据是否完全导入了数据库,即txt中的行数是否和数据库中的行数是否一致

清理hosts文件的方法

如何清理hosts文件,hosts文件是存储映射IP地址和主机名规定的文档。如果hosts文件被修改了的话,可能会导致进入网站时会跳转到广告

文章回顾

大家看了本文C# 使用反射调用方法_MethodInfo.Invoke方法的精彩教程资源内容,是不是对C# 使用反射调用方法_MethodInfo.Invoke方法了解更多,真心希望C# 使用反射调用方法_MethodInfo.Invoke方法能帮助到你, 小编会一直给你带来更多教程资源文章信息。

声明:本站内容和图片来源于网络和读者投稿,本站无法甄别投稿用户享有著作权,根据《信息网络传播权保护条例》,如果转载的作品侵犯了您的权利,请在一个月内通知我站及时删除(serviceaffair#outlook.com #改成@)。https://www.shawanolakecottagemartzke.com/121097.html
返回顶部