zoukankan      html  css  js  c++  java
  • C#学习笔记(30)——系统自带委托Func和Action

    说明(2017-11-23 10:46:33):

    1. Func有返回值,Action无返回值,以后就不用定义delegate委托了。

    2. 不过还是不知道什么时候该用委托,蒋坤在讲完事件后,留了个作业,就是经典的窗体传值,试试看能不能自己做出来。

    使用Func求水仙花数:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace _00_Test
    {
    
        class Program
        {
            static void Main(string[] args)
            {
                List<int> list = new List<int>();
                for (int i = 100; i < 1000; i++)
                {
                    list.Add(i);
                }
                int[] nums = MyWhere(list.ToArray(), e =>
                {
                    int n1 = e % 10;
                    int n2 = e / 10 % 10;
                    int n3 = e / 100;
                    return n1 * n1 * n1 + n2 * n2 * n2 + n3 * n3 * n3 == e;
                });
    
            }
            //Func有返回值,Action无返回值,以后就不用定义delegate委托了。
            public static int[] MyWhere(int[] nums, Func<int, bool> Foo)
            {
                List<int> list = new List<int>();
                foreach (int n in nums)
                {
                    if (Foo(n))
                    {
                        list.Add(n);
                    }
                }
                return list.ToArray();
            }
        }
    }
  • 相关阅读:
    postman发送请求携带Cookie
    maven打包相关配置
    springboot使用redis的keyspace notifications 实现定时通知
    JSON使用
    jdk1.8的一些特性
    Mysql--基础(一)
    04 difflib和filecmp
    08 存储引擎
    03 dnspython模块的应用
    02 IPy模块的应用
  • 原文地址:https://www.cnblogs.com/Jacklovely/p/7883699.html
Copyright © 2011-2022 走看看