• 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();
            }
        }
    }
  • 相关阅读:
    delphi XE8 for android ----一个无意闯入的世界
    不能Ping和telnet的
    syslog-ng内容讲解
    《信息安全系统设计与实现》学习笔记7
    缓冲区溢出实验
    2.3.1测试
    鲲鹏服务器测试
    cat userlist
    需求分析
    《信息安全系统设计与实现》学习笔记5
  • 原文地址:https://www.cnblogs.com/Jacklovely/p/7883699.html
Copyright © 2020-2023  润新知