예제 #1
0
        public static void Transfer()
        {
            //使用方法给上述委托赋值,并运行该委托
            Person       person1       = new Person();
            ProvideWater provideWater1 = new ProvideWater(UseDelegate);

            Console.WriteLine("used method");
            Console.WriteLine(provideWater1(person1));

            //使用匿名方法给上述委托赋值,并运行该委托
            ProvideWater provideWater2 = delegate(Person person)
            {
                return(2);
            };

            Console.WriteLine("used anonymous method");
            Console.WriteLine(provideWater2(person1));

            //使用lambda表达式给上述委托赋值,并运行该委托
            ProvideWater provideWater3 = p => 3;

            Console.WriteLine("used lambda");
            Console.WriteLine(provideWater3(person1));

            //将ProvideWater的返回值输出
            ProvideWater provideWater4 = new ProvideWater(UseDelegate);

            Console.WriteLine("used GetWater() get a value");
            Console.WriteLine(GetWater(provideWater4));
        }
예제 #2
0
파일: DelegateMothed.cs 프로젝트: ywq001/-
        public static void assginWay()
        {
            //使用方法给委托赋值
            Person       person1       = new Person();
            ProvideWater provideWater1 = new ProvideWater(assignDelegate);

            Console.WriteLine(provideWater1(person1));

            //使用匿名方法给委托赋值
            ProvideWater provideWater2 = delegate(Person person)
            {
                return(2);
            };

            Console.WriteLine(provideWater2(person1));

            //使用lambda表达式给上述委托赋值,并运行该委托
            ProvideWater provideWater3 = p => 3;

            Console.WriteLine(provideWater3(person1));

            //将ProvideWater的返回值输出
            ProvideWater provideWater4 = p => 4;

            Console.WriteLine(GetWater(provideWater4));
        }
예제 #3
0
        //声明一个方法GetWater(),该方法接受ProvideWater作为参数,并能将ProvideWater的返回值输出
        public static int GetWater(ProvideWater provideWater)
        {
            Person person = new Person();

            //provideWater = new ProvideWater(UseDelegate);
            return(provideWater(person));
        }
예제 #4
0
        public static void ExecuteWeituo()
        {
            //方法给委托赋值
            ProvideWater provideWater = new ProvideWater(BigFriend);

            Console.WriteLine(Person.GetWater(provideWater));
            ProvideWater provideWater1 = new ProvideWater(SmallFriend);

            Console.WriteLine(Person.GetWater(provideWater1));

            //匿名方法
            ProvideWater provideWater3 = delegate(Person person)
            {
                Console.WriteLine("匿名方法");
                return(person.waternumber += 5);
            };

            Console.WriteLine(Person.GetWater(provideWater3));
            //lambda表达式

            ProvideWater provideWater4 = (Person person) =>
            {
                Console.WriteLine("lambda表达式方法");
                return(person.waternumber += 6);
            };

            Console.WriteLine(Person.GetWater(provideWater4));
        }
예제 #5
0
        static void Main(string[] args)
        {
            ProvideWater provideWater = new ProvideWater(BigFriend);

            Console.WriteLine(Person.GetWater(provideWater));
            ProvideWater provideWater1 = new ProvideWater(SmallFriend);

            Console.WriteLine(Person.GetWater(provideWater1));
        }
예제 #6
0
        public static void InvokeDelegate()
        {
            ProvideWater provide = new ProvideWater(SetValue); //方法个委托赋值

            provide += delegate(Person person)                 //匿名方法赋值
            {
                return(-1);
            };

            provide += person => - 1;                          //Lambda赋值

            provide(new Person());
        }
예제 #7
0
파일: Person.cs 프로젝트: xqgg/peng
        public static void Do()
        {
            //使用:
            //1.方法
            Person       man     = new Person();
            ProvideWater provide = new ProvideWater(UseDelegate);

            Console.WriteLine(provide(man));

            //2.匿名方法
            provide = delegate(Person person)
            {
                return(2);
            };
            Console.WriteLine(provide(man));

            //3.lambda表达式
            provide = p => 3;
            Console.WriteLine(provide(man));

            //声明一个方法GetWater(),该方法接受ProvideWater作为参数,并能将ProvideWater的返回值输出
            GetWater(provide);
        }
예제 #8
0
파일: Program.cs 프로젝트: Edwin521/17bang
        static void Main(string[] args)
        {
            User    user = new User();
            Article art  = new Article();

            art.Publish();

            Console.WriteLine(DateTime.Now.ToString());


            DLinkNode dLinkNode1 = new DLinkNode();
            DLinkNode dLinkNode2 = new DLinkNode();
            DLinkNode dLinkNode3 = new DLinkNode();
            DLinkNode dLinkNode4 = new DLinkNode();

            dLinkNode1.AddAfter(dLinkNode2);
            dLinkNode2.AddAfter(dLinkNode3);
            dLinkNode3.AddAfter(dLinkNode4);

            foreach (DLinkNode item in dLinkNode1)
            {
                Console.WriteLine(item);
            }


            //方法给委托赋值
            ProvideWater provideWater = new ProvideWater(AssignToDlg);

            //匿名方法给委托赋值
            ProvideWater provideWater2 = delegate(Person person)
            {
                return(person.weight--);
            };
            // lambda表达式给委托赋值
            ProvideWater provideWater3 = p => p.weight--;

            Console.WriteLine(GetWater(provideWater3));

            ///////////////////////////////////////////////////////////////////////
            ///构建文章,评论,评价,关键字的关系。
            User lzb = new User {
                Name = "李智博", Password = "******"
            };
            User xy = new User {
                Name = "小鱼", Password = "******"
            };
            User fg = new User {
                Name = "飞哥", Password = "******"
            };
            IList <User> users = new List <User> {
                lzb, xy, fg
            };



            Comment comment1 = new Comment {
                main = "你写的真不错"
            };
            Comment comment2 = new Comment {
                main = "你的文笔真不错"
            };
            Comment comment3 = new Comment {
                main = "写的不是很好,不符合我的价值观"
            };
            Comment comment4 = new Comment {
                main = "写的不错,给你100分"
            };
            Comment comment5 = new Comment {
                main = "你是我见过写的最差的"
            };
            Comment comment6 = new Comment {
                main = "写的不是很符合我的逻辑,感觉很凌乱,继续加油哦"
            };
            IList <Comment> Comments = new List <Comment> {
                comment1, comment2, comment3, comment4, comment5, comment6
            };

            Keyword <Article> java = new Keyword <Article> {
                Word = "java的应用"
            };
            Keyword <Article> c = new Keyword <Article> {
                Word = "c应用"
            };
            Keyword <Article> css = new Keyword <Article> {
                Word = "css的应用"
            };
            Keyword <Article> jquery = new Keyword <Article> {
                Word = "jquery的应用"
            };
            Keyword <Article> it = new Keyword <Article> {
                Word = "编程语言"
            };
            Keyword <Article> csharp = new Keyword <Article> {
                Word = "编程语言之csharp"
            };
            Keyword <Article> net = new Keyword <Article> {
                Word = "编程世界之-.net"
            };
            IList <Keyword <Article> > keywords = new List <Keyword <Article> > {
                java, c, css, jquery, it
            };

            Article Article1 = new Article()
            {
                Title       = "it学习入门",
                Main        = "it入门需要做些什么准备呢,咱们。。。",
                Author      = fg,
                PublishTime = new DateTime(2020, 10, 1),
                keywords    = new List <Keyword <Article> > {
                    it, csharp
                },
                Comment = new List <Comment> {
                    comment3
                }
            };



            Article Article2 = new Article
            {
                Title       = "高效的学习效率",
                Main        = "怎样提高我们的学习效率呢。。。",
                Author      = fg,
                PublishTime = new DateTime(2019, 10, 1),
                keywords    = new List <Keyword <Article> >()
                {
                    it, java, c
                },
                Comment = new List <Comment> {
                    comment4
                }
            };
            Article Article3 = new Article
            {
                Title       = "怎样选择编程语言",
                Main        = "编程语言需要结合。。。。",
                Author      = fg,
                PublishTime = new DateTime(2019, 6, 1),
                keywords    = new List <Keyword <Article> >()
                {
                    it, css
                },
                Comment = new List <Comment>()
                {
                    comment5
                }
            };
            Article article4 = new Article
            {
                Title    = "编程语言的魅力",
                Author   = xy,
                keywords = new List <Keyword <Article> >()
                {
                    it, css, jquery
                },
                Comment = new List <Comment>()
                {
                    comment1, comment2
                },
                PublishTime = new DateTime(2020, 11, 1)
            };
            List <Article> Articles = new List <Article> {
                Article1, Article2, Article3, article4
            };

            Problem problem1 = new Problem
            {
                Author      = lzb,
                Reward      = 13,
                PublishTime = new DateTime(2020, 1, 20),
                Main        = "求助大佬关于c#委托方面的知识",
                Title       = "c#方面的求助",
                comments    = new List <Comment> {
                    comment6
                },
            };

            IList <Problem> problems = new List <Problem> {
                problem1
            };


            //文章文章添加评价
            Appraise appraise1 = new Appraise {
                Voter = lzb
            };

            appraise1.Agree();
            Article1.appraises.Add(appraise1);

            Appraise appraise2 = new Appraise {
                Voter = xy
            };

            appraise2.Disagree();
            Article1.appraises.Add(appraise2);
            //一个关键字也可以对应多个文章
            it.Articles = new List <Article> {
                Article1, Article2, Article3
            };
            //文章可以有多个评论
            Article1.Comment = new List <Comment> {
                comment1, comment2
            };
            //每个评论必须有一个对应的文章
            comment3.Article = Article1;


            ////每篇文章都对应着它的作者

            Article1.Author = fg;
            Article2.Author = fg;
            Article3.Author = fg;
            article4.Author = xy;


            //ContentService kk = new ContentService();
            //Article news = new Article();
            //kk.Publish(news);
            //Console.WriteLine(news.PublishTime);

            //在之前“文章 / 评价 / 评论 / 用户 / 关键字”对象模型的基础上,添加相应的数据,然后完成以下操作:

            //用linq方法改写以前的表达式

            //找出“飞哥”发布的文章
            var Find_dfg = Articles.Where(a => a.Author == fg);
            //找出2019年1月1日以后“小鱼”发布的文章
            var Find_xy = Articles.Where(a => a.Author == xy && a.PublishTime > new DateTime(2019, 1, 1));
            //按发布时间升序 / 降序排列显示文章
            var Ascd = Articles.OrderBy(a => a.PublishTime);
            var Desc = Articles.OrderByDescending(a => a.PublishTime);


            //统计每个用户各发布了多少篇文章
            var Fg_article = Articles.Where(a => a.Author == fg).GroupBy(a => a.Author);
            var Xy_article = Articles.Where(a => a.Author == xy).GroupBy(a => a.Author);
            //找出包含关键字“C#”或“NET”的文章
            var Csharp_kw = Articles.Where(a => a.keywords.Any(k => k.Word == "c#"));
            var Net_kw    = Articles.Where(a => a.keywords.Any(k => k.Word == ".NET"));

            //找出评论数量最多的文章
            var Article_Comment_Max = Articles.OrderByDescending(a => a.Comment.Count()).First();

            //找出每个作者评论数最多的文章
            var Fg_Comment_Max = Articles.Where(a => a.Author == fg).OrderByDescending(a => a.Comment.Count()).First();
            var Xy_Comment_Max = Articles.Where(a => a.Author == xy).OrderByDescending(a => a.Comment.Count()).First();

            //找出每个作者最近发布的文章
            var Fg_Article_Rec = Articles.Where(a => a.Author == fg).OrderByDescending(a => a.PublishTime).First();
            var Xy_Article_Rce = Articles.Where(a => a.Author == xy).OrderByDescending(a => a.PublishTime).First();


            //找出每一篇求助的悬赏都大于5个帮帮币的求助作者
            var resualt = problems.Where(p => p.Reward > 5).GroupBy(p => p.Author);


            //Console.WriteLine(HomeWork<int>.BinarySeek(new System.Collections.Generic.List<int> { 1, 5, 76, 8, 9, 0, 43, 6, 3, 5 }, 0));

            ///字符串
            //Console.WriteLine(mimicJoin("-", new string[] {"众所周知", "飞哥", "的", "颜值","是","一百分" }));
            //Console.WriteLine(GetCount("13212*212-212", "212"));
            //Console.WriteLine(GetCount("111234512", "12"));
            //封装一个方法,可以修改Content的CreateTime和PublishTime
            //DateTime lw = new DateTime(2023, 3, 4);

            //Content article = new Content("文章");
            //article.GetType()
            //    .GetProperty("CreateTime", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(article, lw);
            //Console.WriteLine();



            //Console.WriteLine(Program.findPrimeNum(1, 10));

            //TokenManager tokenManager = new TokenManager();
            //User user = new User("lls", "1234");
            //Console.WriteLine(user.ToString());

            //Console.WriteLine(user);

            //Article js = new Article
            //{
            //    title = "title1",
            //    Author = new User("lzb", "333")
            //};

            //User lls = new User("lls", "123");
            //js.AgreedBy(lls);

            //new Article().AgreedBy(new User("lls", "1234"));


            //ISendMessage lzb = new User("lzb","123");///调用显示接口
            //User lls = new User("lls", "333");

            //lzb.Send(lls);

            //Console.WriteLine(time.GetDate(new DateTime(2020,2,27), 3));
            //Console.WriteLine(time.GetDate(new DateTime(2020,2,27), 1));
            //Console.WriteLine(time.GetDate(new DateTime(2020,12,30), 1));
            //Console.WriteLine(time.GetDate(new DateTime(2020,1,1), 1));

            //Console.WriteLine(time.GetDateofmondy(2021));
            //Console.WriteLine(time.GetDateofmondy(2022));
            //Console.WriteLine(time.GetDateofmondy(2023));
            //Console.WriteLine(time.GetDateofmondy(2024));


            //time.GetWeeks(new DateTime(2020, 1, 6));


            //TokenManager lzb = new TokenManager();
            //lzb._token = lzb._token | Token.Admin;///存入权限身份
            //lzb._token = lzb._token ^ Token.Blogger;//剥夺权限身份


            //Console.WriteLine((lzb._token & Token.Newbie) == Token.Newbie);//查看是否存在这个权限



            //用代码证明struct定义的类型是值类型
            //bed dream = new bed();
            //dream = null;///值类型不能赋值为null
            //User lzb = new User("lzb","123");
            //lzb = null;///同样的由class定义的引用类型就可以赋值为null

            //Suggest lzb = new Suggest();
            //Console.WriteLine(lzb._kind);
            //Article lz = new Article();
            //Console.WriteLine(lz._kind);


            // FactoryContext lzb = new FactoryContext();
            //FactoryContext a = FactoryContext.foo();
            //FactoryContext b = FactoryContext.foo();
            //MimicStack.MimicStack.Push(123);
            //MimicStack.MimicStack.Push(124);
            //MimicStack.MimicStack.Push(123);

            /* FactoryContext a = new FactoryContext();*////构造函数设为私有后,新new的时候就会报错


            //problem lzb = new problem();
            //lzb[1] = "123";
            //lzb[2] = "456";
            //lzb[3] = "789";
            //lzb[0] = "22";
            //Console.WriteLine(lzb[2]);

            //problem lzb = new problem("lzb");

            //problem lw = new problem("");

            //User zdh = new User("空", "ki");
            //Console.WriteLine(zdh.Name);

            //Console.WriteLine(zdh.Password);

            ///调用函数
            ///
            //string output;
            //LZBC.user.Register("1234", "2345", "3456",  "4567", "6789",out output);
            //if (LZBC.user.Register("1234", "2345", "3456", "4567", "6789", out output))
            //{
            //    Console.WriteLine(output);
            //}
            //else
            //{
            //    Console.WriteLine(output);
            //}



            //            string num;
            //            if (logOn("12", "13", "14", out num)
            //)
            //            {
            //                Console.WriteLine(num);
            //            }
            //            else
            //            {
            //                Console.WriteLine(num);

            //            }


            //Console.WriteLine(BinarySeek(new int[] { 1, 3, 5, 6, 8, 12, 24 }, 0, 7, 12));
            //Console.WriteLine(BinarySeek2(new int[] { 1, 3, 5, 6, 8, 12, 24, 34,75 },75 ));
            //GetArray(12, 12, 12);
            //GuessMe();
            //Console.WriteLine(GetAverage(new double[] { 23.45, 12.3, 34.5 }));
            //findPrimeNum(10,30);//找质数
            /// Console.WriteLine(getMax(new double[] { 23.1, 44, 32, 13 }));
            //getMax(new double[] { 23.1, 44, 32, 13 });
            //twoDimensional();//数组下标
            //GetAverage(1200, 43);//平均成绩
            //Console.WriteLine(GetAverage(1200, 43));

            // Console.WriteLine(logOn("123", "234", "345"));//登录
            //GuessMe(12);//猜数字

            ///  //getSum(1, 2);
            //Console.WriteLine(getSum(1, 2));
            //getProduct(2, 3);
            //Console.WriteLine(getProduct(2, 3));
            //differencing(23, 21);
            //Console.WriteLine(differencing(23, 21));
            //QUOTIENT(4, 3);
            //Console.WriteLine(QUOTIENT(6,2.4));
        }
예제 #9
0
파일: Program.cs 프로젝트: Edwin521/17bang
        // 声明一个方法GetWater(),该方法接受ProvideWater作为参数,
        //并能将ProvideWater的返回值输出
        public static int GetWater(ProvideWater Provider)
        {
            Person person = new Person();

            return(Provider(person));
        }
예제 #10
0
        public int GetWater(ProvideWater provide)   //GetWater()方法
        {
            Person person = new Person();

            return(provide(person));
        }
예제 #11
0
        static void Main(string[] args)
        {
            #region ADO.NET HomeWork
            //            作业:
            //构建一个DBHelper,可以提供:

            //    封装过后的ExecuteNonQuery() / ExecuteScalar() / ExecuteReader()方法
            //        由外部控制开闭(Open() / Close())的长连接(LongConnection)
            //    ExecuteNonQuery()使用长连接的重载


            //使用上述DBHelper,完成以下操作:

            //    将用户名和密码存入数据库:Register()
            //    根据用户名和密码检查某用户能够成功登陆:Logon()
            //    如果用户成功登陆,将其最后登录时间(LatestLogonTime)改成当前时间
            //    批量标记若干Id的Message为已读:MarkHasRead(int[] messageIds)
            //    查找出最近登录的若干个同学:IList<User> GetLatestLogon(int amount)
            //    用事务完成帮帮币转移方法:void Sell(User buyer, int amount),当前用户的帮帮币减少amount枚,买家(buyer)的帮帮币增加amount枚


            #endregion



            string connectionString = @"Data Source=-20191126PKLSWP;Initial Catalog=17bang;Integrated Security=True;";
            using (DbConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
            }

            #region 双链foreach和max作业

            DoubleLinkNode node1 = new DoubleLinkNode {
                value = 1
            };
            DoubleLinkNode node2 = new DoubleLinkNode {
                value = 2
            };
            DoubleLinkNode node3 = new DoubleLinkNode {
                value = 3
            };
            DoubleLinkNode node4 = new DoubleLinkNode {
                value = 4
            };
            DoubleLinkNode node5 = new DoubleLinkNode {
                value = 5
            };

            node2.InsertAfter(node1);
            node3.InsertAfter(node2);
            node5.InsertAfter(node3);


            foreach (var item in node1)
            {
                Console.WriteLine(((DoubleLinkNode)item).value);
            }
            //DoubleLink Max
            DoubleLinkNode.Max(node1);

            #endregion


            #region 2020.4.14  5.在Main()函数调用ContentService时,捕获一切异常,并记录异常的消息和堆栈信息

            User    wpz     = new User("wpzwpz", "1231231");
            Problem problem = new Problem()
            {
                Reward = 2
            };
            Content content = new Content("王月半子")
            {
                Reward = problem, Author = wpz
            };
            try
            {
                ContentService contentService = new ContentService();
                //我的理解,这个方法调用里已经有了各种抛异常的机制,
                //那我这里就不用在写Throw了,如果有意外的异常catch就可以用了
                contentService.Publish(content);
            }
            catch (Exception Record)
            {
                string path = @"C:\Users\Administrator\source\repos\luckstack3\Captcha\ForContentService.txt";
                using (StreamWriter writer = File.AppendText(path))
                {
                    DateTime date = DateTime.Now;//设置日志时间
                    string   time = date.ToString("yyyy-mm-dd HH:mm:ss");


                    //日志存放
                    //writer = File.AppendText(path);
                    writer.WriteLine("异常时间" + time);
                    writer.WriteLine("异常对象" + Record.Source);
                    writer.WriteLine("调用堆栈" + Record.StackTrace.Trim());
                    writer.WriteLine("调用堆栈" + Record.ToString());

                    writer.Flush();
                }
                throw;
            }
            #endregion

            #region Generic Method Homework Area
            //1.声明一个委托:打水(ProvideWater),可以接受一个Person类的参数,返回值为int类型 【已完成】
            ProvideWater getWater = TakeWater;

            Person water = new Person();
            //2-1.方法 【已完成】
            getWater(water);
            //2-2.匿名方法 【已完成】
            ProvideOtherWater(water);
            //2-3.lambda表达式
            ProvideLambdaWater(water);
            //3.声明一个方法GetWater(),该方法接受ProvideWater作为参数,并能将ProvideWater的返回值输出
            GetWater(getWater);
            #endregion

            #region http://17bang.ren/Article/537    C#进阶:Linq方法   找出每个作者最近发布的一篇文章
            //找出每个作者最近发布的一篇文章
            LinqMethod.find_AuthorRecentlyArticle();

            //为求助(Problem)添加悬赏(Reward)属性,并找出每一篇求助的悬赏都大于5个帮帮币的文章作者
            LinqMethod.SearchReward();
            #endregion

            #region C#   http://17bang.ren/Article/520  C#进阶:Linq-1:where/order/group/select
            LinqMethod.Find_DFG_Article();

            LinqMethod.Find_YU_Article();

            LinqMethod.AscendingAndDescendingArticle();

            LinqMethod.CountArticle();

            LinqMethod.FindSpecefiedKeyWord();

            LinqMethod.MaxCommentsOfArticle();

            LinqMethod.MaxCommentsOfAuthor();
            #endregion

            #region 面向对象和C#基础作业(old)

            #region 值的值传递和引用  之前作业完结

            //int a = 18;

            //HomeWork person = new HomeWork();//值的值传递
            //person.ValuePass(a);
            //Console.WriteLine(a);
            //Console.WriteLine("------------------------");

            //HomeWork otherPerson = new HomeWork();//值的引用传递
            //otherPerson.ReferencePass(ref a);
            //Console.WriteLine(a);
            //Console.WriteLine("--------------------------");

            //HomeWork name = new HomeWork { _name = "王月半子" };//引用类型的值传递
            //ChangeName(name);
            //Console.WriteLine(name._name);
            //Console.WriteLine("--------------------------");

            //HomeWork newName = new HomeWork { _name = "王月半子" };//引用类型的引用传递
            //ChangeingName(ref newName);
            //Console.WriteLine(newName._name);



            #endregion

            #region 第一天作业 观察“一起帮”的: 功能作业https://zhuanlan.zhihu.com/p/92362781
            //User of class method.
            //Entity.User User = new Entity.User();
            //User.Register();
            //User.Login();

            ////problem of class method ( inside null)
            //Entity.Problem Problem = new Entity.Problem();
            //Problem.Publish();

            ////HeloMoney of call method (inside null)

            //Entity.HelpMoney Helomoney = new Entity.HelpMoney();
            //Helomoney.BodyShow();

            #endregion

            #region Secend Day Homework. https://zhuanlan.zhihu.com/p/92470130
            //1.user.Password在类的外部只能改不能读
            //Entity.User Password = new Entity.User();
            //Password.Password = "******";

            //2.如果user.Name为“admin”,输入时修改为“系统管理员”
            //Entity.User user = new Entity.User();
            //user.UserName = "******";

            //3.problem.Reward不能为负数
            //Entity.Problem problem = new Entity.Problem();
            //problem.Reward = -1;


            //调用这些类的有参/无参构造函数,生成这些类的对象,调用他们的方法

            //3. 一起帮的求助可以有多个(最多10个)关键字,请为其设置索引器,以便于我们通过其整数下标进行读写
            //Entity.Problem problem = new Entity.Problem();
            //Console.WriteLine(problem[52]);

            //设计一种方式,保证:每一个Problem对象一定有Body赋值每一个User对象一定有Name和Password赋值
            //Go to (Problem Page) OR (User Page )watch.

            #endregion

            #region Third Day Homework.  https://zhuanlan.zhihu.com/p/95261748
            //1.Publish():发布一篇求助,并将其保存到数据库
            //Entity.Problem problem = new Entity.Problem();
            //problem.HelpMe();

            ///3.设计一个类FactoryContext,保证整个程序运行过程中,
            ///无论如何,外部只能获得它的唯一的一个实例化对象。(提示:设计模式之单例)
            ///
            //new Entity.FactoryContext().Show(); // probably is private function make this red line...


            ///4.想一想,为什么Publish()方法不是放置在User类中呢?
            ///用户(user)发布(Publish)一篇文章(article)
            ///,不正好是user.Publish(article) 么?
            ///
            ///这里也有发布的啊,如果那里有需要发布,继承一个就好了,或者直接引用这里的方法就可以。
            ///如果这么说对的话,我还可以继续说,如果说的不对那就当我没说。



            ///5.自己实现一个模拟栈(MimicStack)类,入栈出栈数据均为int类型,包含如下功能:
            ///5.1出栈Pop(),弹出栈顶数据
            ///5.2入栈Push(),可以一次性压入多个数据
            ///5.3 出 / 入栈检查,
            ///5.4如果压入的数据已超过栈的深度(最大容量),提示“栈溢出”如果已弹出所有数据,提示“栈已空”
            //MimicStack stack = new MimicStack();
            //stack.push(223573);
            //stack.pop();
            //stack.pop();
            //stack.push(123);
            //stack.push(22743);
            //stack.push(233);
            //stack.push(22213);
            //stack.pop();
            //stack.push(32213);
            //stack.push(52213);
            //stack.push(2213);
            //stack.pop();
            //stack.push(22813);
            //stack.push(22313);
            //stack.push(224213);
            //stack.push(92212463);
            //stack.push(1);
            //stack.push(1);
            //stack.push(1);
            //stack.push(1);
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();
            //stack.pop();


            //3.实例化文章和意见建议,调用他们:继承自父类的属性和方法自己的属性和方法
            // it's for parents
            //Entity.Content content = new Article();//here is for article page.
            //content.Release();
            //content = new Problem();//here is for problem page.
            //content.Release();
            //content = new Suggest();//here is for suggest page.
            //content.Release();
            //Article article = new Article();
            //4.再为之前所有类(含User、HelpMoney等)抽象一个基类:Entity,
            //包含一个只读的Id属性。试一试,Suggest能有Id属性么?

            ///只是把任务要求造出来了,具体啥意思也不知道。suggest ID指的是啥???
            ///这个作业后补。
            #endregion

            #region Fourth Day Homework "多态"  https://zhuanlan.zhihu.com/p/93053223
            ///1.添加一个新类ContentService,其中有一个发布(Publish())方法:
            /// 如果发布Article,需要消耗一个帮帮币
            /// 如果发布Problem,需要消耗其设置悬赏数量的帮帮币
            /// 如果发布Suggest,不需要消耗帮帮币
            ///最后将内容存到数据库中,三个类存数据库的方法是完全一样的,
            ///现在用Console.WriteLine()代替。根据我们学习的继承和多态知识,实现上述功能。
            ///
            ///
            ///maybe i made big mistake.homework write not like this.---T_T||...
            //ContentService contentService = new ContentService("Article",20);
            //contentService.publish();

            #endregion

            #region Fifth Day  思考之前的Content类,该将其抽象成抽象类还是接口?https://zhuanlan.zhihu.com/p/93224519
            ///1.思考之前的Content类,该将其抽象成抽象类还是接口?为什么?并按你的想法实现。
            ///
            //思考应该用interface接口,但是一改Errors爆满,无从下手改。。。。

            ///2.一起帮里的求助总结、文章和意见建议,以及他们的评论,
            ///都有一个点赞(Agree)/踩(Disagree)的功能,赞和踩都会增减作者及评价者的帮帮点。
            ///能不能对其进行抽象?如何实现?
            ///

            #endregion

            #region Six Day 1.用代码证明struct定义的类型是值类型 栈的学费是按周计费的,所以请实现这两个功能:
            //1.用代码证明struct定义的类型是值类型     (MyClass and MyStruct at this page.)
            //MyClass myClass = new MyClass();
            /*myClass._test = 23;*/  //这里的23是赋值到一个地址里面去。
                                     //MyStruct myStruct = new MyStruct();
            /*myStruct._test = 23;*/ //这里是值类型。

            ///	1.函数GetDate(),能计算一个日期若干(日/周/月)后的日期
            ///2.给定任意一个年份,就能按周排列显示每周的起始日期,如下图所示:
            //DataTimeCount.GetWeek(2000);

            #endregion

            #region Seven Day homework   about Token
            //TokenManager tokenManager = new TokenManager();
            //tokenManager.Add(Token.Admin);
            //tokenManager.Add(Token.Blogger);
            //tokenManager.Add(Token.Registered);
            //tokenManager.Remove(Token.Blogger);
            //tokenManager.Has(Token.Admin);
            #endregion

            #region https://zhuanlan.zhihu.com/p/93458057C#-面向对象-万物皆对象:Object和装箱拆箱

            ///1.思考dynamic和var的区别,并用代码予以演示
            ///
            //请忽略命名,命名采用var的第一个字母,和一个随便的i,dynamic也是一样
            //var Vi = "88";
            //dynamic Di = "88";

            //区别在于,var是推倒类型,在使用中因为vi被推导为string类型所以无法完成表达式
            //无法通过编译,所以直接报错。
            //Console.WriteLine(Vi - 8);
            //dynamic是动态类型,在编译时默认跳过,所以不会有报错的发生,但如果运行时候会报运行错误
            //结果是一样的。
            //Console.WriteLine(Di-8);


            //2.构造一个能装任何数据的数组,并完成数据的读写
            //我不知道还有什么类型了,字符串,数字,元组,bool,小数,数组,应该差不多了。
            //object[] AnyArray = { "王胖子很帅", 26, (23, "17cm"), new Student() ,true ,888.8,new int [17,18,19,20,22]};
            //for (int i = 0; i < AnyArray.Length-1; i++)
            //{//想不到我现在竟然可以随手就写一个完美的循环出来。
            //    Console.WriteLine(AnyArray[i]);
            //}
            //Console.WriteLine(AnyArray);

            //3.使用object改造数据结构栈(Stack),并在出栈时获得出栈元素
            //都已经如此完美了,还怎么优化。。。

            ///
            #endregion

            #region https://zhuanlan.zhihu.com/p/93440022C#-面向对象-反射和特性
            //2.在Content之外封装一个方法,可以修改Content的CreateTime和PublishTime
            //FixTime.FixContentTime(2019, 10, 19);

            ///3.自定义一个特性HelpMoneyChanged(帮帮币变化):
            ///1.该特性只能用于方法
            ///2.有一个构造函数,可以接受一个int类型的参数amount,表示帮帮币变化的数量
            ///3.有一个string类型的Message属性,记录帮帮币变化的原因
            ///
            //作业在User页面

            ///5.用反射获取Publish()上的特性实例,输出其中包含的信息
            ///
            //这个地方有BUG,把自己写迷糊了。歇会儿换个思路,如果换不出来就等飞哥来换。
            //思路是这样的,我要使用GetHM这个函数,必须有一个参数,参数需要找Publish这个方法要
            //要找publish方法首先我需要有一个contentservice这个对象,有了这个对象,还得给publish传参...我的天
            //ContentService service = new ContentService();
            //service = service.Publish(Article article);
            //GetPublish.GetHM(service);
            #endregion

            #region https://zhuanlan.zhihu.com/p/93747718 C#-面向对象:string还是StringBuilder?
            ///确保文章(Article)的标题不能为null值,也不能为一个或多个空字符组成的字符串,
            ///而且如果标题前后有空格,也予以删除
            ///
            //Article wpz1 = new Article(string.Empty);
            //Article wpz2 = new Article("    ");
            //Article wpz3 = new Article(null);
            //Article wpz4 = new Article("");
            //Article wpz5 = new Article(" ");
            //Article wpz = new Article("   王胖子比飞哥帅的多   ");


            //设计一个适用的机制,能确保用户(User)的昵称(Name)不能含有admin、17bang、管理员等敏感词。
            //User wpz4 = new User("qqadminw", "~qweqwe");
            //User wpz5 = new User("wwadminw", "!qweqwe");
            //User wpz6 = new User("adminee", "@qwe123");
            //User wpz7 = new User("adminee", "@qwe123");
            //User wpz8 = new User("qq17bang", "@qwe123");
            //User wpz9 = new User("qq17bangww", "@qwe123");


            ///确保用户(User)的密码(Password):长度不低于6
            ///必须由大小写英语单词、数字和特殊符号(~!@#$%^&*()_+)组成
            ///
            //这个密码应该还差点东西没写对
            //User user = new User("", "abcabc");
            //User user1 = new User("", "==abcabc");

            //User wpz = new User("admin", "~!@#  $%^&*()_+");
            //User wpz1 = new User("admin", "~qw---eqwe");
            //User wpz2 = new User("admin", "!qweqwe");
            //User wpz3 = new User("admin", "@qwe123");



            #endregion


            #endregion

            #region Practies area.. Here is not homeword,just selftry.


            //Self wang = new Self();
            //Type typeinfo = typeof(Self);
            //FieldInfo wangpz = typeinfo.GetField("_try", BindingFlags.NonPublic | BindingFlags.Instance);
            //object Try = wangpz.GetValue(wang);
            //Console.WriteLine(Try);

            //Self yb = new Self();
            //Type diyibu = typeof(Self);
            //FieldInfo dierbu = diyibu.GetField("_iTry", BindingFlags.NonPublic |BindingFlags.Instance| BindingFlags.GetProperty);
            //object disubu = dierbu.GetValue(yb);
            //Console.WriteLine(disubu);
            //disubu = 222;
            //Console.WriteLine(disubu);
            //Self self = new Self();
            //Console.WriteLine(self);


            //object tlzz = new Student();
            //NowTry.Praise(tlzz);
            //object wpz = new Teacher();
            //NowTry.Praise(wpz);

            //string name = string.Empty;
            //if (student ==null)
            //{
            //    name = "无姓名";
            //}
            //else
            //{
            //    name = student.name;
            //}

            //string name = student == null ? "无姓名" : student.name;
            //student student =null;

            //Console.WriteLine(student?.IsMale);
            //bool? gender = student?.IsMale;
            //gender = false;

            //int[] vs = new int[] { 16, 23, 25, 22 };
            //List<int> ages = new List<int> {16,23,25,22 };

            //IEnumerator<int> enumerator = ages.GetEnumerator();
            //while (enumerator.MoveNext())
            //{
            //    Console.WriteLine(enumerator.Current);
            //}


            //LinkedList


            #endregion
        }
예제 #12
0
 public static ProvideWater GetWater(ProvideWater provide)
 {
     return(provide);
 }
예제 #13
0
파일: Person.cs 프로젝트: xqgg/peng
 public static void GetWater(ProvideWater provideWater)
 {
     Console.WriteLine($"得到水{provideWater(new Person())}");
 }
예제 #14
0
 public int GetWater(ProvideWater providewater)
 {
     return(providewater(this));
 }
예제 #15
0
파일: DelegateMothed.cs 프로젝트: ywq001/-
        //声明一个方法GetWater(),该方法接受ProvideWater作为参数,并能将ProvideWater的返回值输出
        public static int GetWater(ProvideWater provide)
        {
            Person person = new Person();

            return(provide(person));
        }
예제 #16
0
 public static void GetWater(ProvideWater provideWater, Person person)
 {
     Console.WriteLine(provideWater(person));
 }
예제 #17
0
 public static int GetWater(Person person, ProvideWater pw)
 {
     return(pw(person));
 }