C#委托简单使用

发布时间:2020-06-18 09:59:35 作者:缘来没法挡
来源:网络 阅读:453

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace 委托01

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("请输入两个int类型数据:");

            int nu1, nu2, result = 0;

            nu1 = int.Parse(Console.ReadLine());

            nu2 = Convert.ToInt32(Console.ReadLine());

            JiSuanDelegate jisun;//声明委托

            if (nu1 % 2 == 0 && nu2 % 2 == 0)

            {

                jisun = GetPlusOu;//实例化委托

                Console.WriteLine("调用了两偶数函数。");

                result = jisun(nu1, nu2);

            }

            else if (nu1 % 2 == 0 || nu2 % 2 == 0)

            {

                jisun = GetSumji;//实例化委托

                Console.WriteLine("调用了非两偶数函数。");

                result = jisun(nu1, nu2);

            }

            Console.WriteLine(result.ToString());

            Console.ReadKey();

        }

        public static int GetSumji(int x, int y)

        {

            return x + y;

        }

        public static int GetPlusOu(int x, int y)

        {

            return x * y;

        }

    }

    delegate int JiSuanDelegate(int i, int j);//定义委托

}


推荐阅读:
  1. C# 委托及事件
  2. C#委托和事件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

委托 delegate

上一篇:python3中的哪个版本更稳定

下一篇:OSSIM中网卡设置注意事项

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》