• 递归


    //递归 
    public class LinC
        {
            public static string Go()
            {
                Func<Func<int, int>, Func<int, int>> fun = child => x => x == 0 ? 1 : x * child(x - 1);
                var F = Recursion<int>.GetRecursion(fun);
                string aa = F(5).ToString();
                return aa;
            }
    
            public static void test()
            {
                List<FileInfo> res = new List<FileInfo>();
                DirectoryInfo dir = new DirectoryInfo(@"E:\AAA");
                //传入参数起作用,返回参数无实际意义,只为补完整函数体
                Func<Func<DirectoryInfo, DirectoryInfo>, Func<DirectoryInfo, DirectoryInfo>> fun = child => x =>
                    {
                        res.AddRange(x.GetFiles());
                        foreach (var read in x.GetDirectories())
                            child(read);
                        //起终止递归的作用
                        return dir;
                    };
    
    
                var F = Recursion<DirectoryInfo>.GetRecursion(fun);
                var ddd = F(dir);
            }
        }
    
    
        public class Recursion<K>
        {
            //自身代理
            delegate T LinDelegate<T>(LinDelegate<T> delageteSelf);
    
            public static Func<Func<Func<K, K>, Func<K, K>>, Func<K, K>> GetRecursionBase()
            {
                LinDelegate<Func<Func<Func<K, K>, Func<K, K>>, Func<K, K>>> self = y => f => x => f(y(y)(f))(x);
                Func<   Func<    Func<K, K>, Func<K, K>   >,        Func<K, K>   > res = self(self);
                return res;
            }
    
            public static Func<K, K> GetRecursion(Func<Func<K, K>, Func<K, K>> fun)
            {
                var F = Recursion<K>.GetRecursionBase();
                Func<K, K> res = F(fun);
                return res;
            }
        }
  • 相关阅读:
    10.16(day54)
    10.17(day55)
    10.15(day53)
    10.14(day52)
    10.12(day51)
    10.11(day50)form表单,css的引入,css选择器,css修改字体属性
    10.10(day49)初识前端,html基础
    9.25(day44)
    9.24(day43)
    9.23(day42)数据库的配置,数据库表的引擎,数据类型,约束条件
  • 原文地址:https://www.cnblogs.com/fm168/p/2969029.html
Copyright © 2020-2023  润新知