From 40efd021ab16802e857fc34837143cc50244459c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=A4=9A=E9=92=B1?= <3381810463@qq.com> Date: Sun, 8 Dec 2024 17:10:06 +0800 Subject: [PATCH] =?UTF-8?q?20241202=E4=BD=9C=E4=B8=9A,20241206=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\344\270\232\347\274\226\350\276\221.md" | 33 +++ ...da\350\241\250\350\276\276\345\274\217.md" | 246 ++++++++++++++++++ 2 files changed, 279 insertions(+) create mode 100644 "\350\256\270\350\211\263/20241202\347\254\224\350\256\2608--\344\275\234\344\270\232\347\274\226\350\276\221.md" create mode 100644 "\350\256\270\350\211\263/20241206\347\254\224\350\256\2609--\344\275\234\344\270\232iLnq\346\237\245\350\257\242\345\222\214Lambda\350\241\250\350\276\276\345\274\217.md" diff --git "a/\350\256\270\350\211\263/20241202\347\254\224\350\256\2608--\344\275\234\344\270\232\347\274\226\350\276\221.md" "b/\350\256\270\350\211\263/20241202\347\254\224\350\256\2608--\344\275\234\344\270\232\347\274\226\350\276\221.md" new file mode 100644 index 0000000..11bc50d --- /dev/null +++ "b/\350\256\270\350\211\263/20241202\347\254\224\350\256\2608--\344\275\234\344\270\232\347\274\226\350\276\221.md" @@ -0,0 +1,33 @@ +## 作业 +1. 控制器内的代码 +```cs +public class BlogsController : Controller +{ + public IActionResult Index(string Keyword) + { + // 判断是否为空 + if(string.IsNullOrEmpty(Keyword)) + { + return View(Db.Blogs); + } + else{ + var list =Db.Blogs.Where(x=>x.Title.Contains(Keyword)|| x.Author.Contains(Keyword) || x.Content.Contains(Keyword)).ToList(); + return View(list); + } + + } +``` +2. view视图内 +```cshtml +
+
+
+ @* *@ + @* *@ + @* 查询 *@ +
+ + +
+
+``` \ No newline at end of file diff --git "a/\350\256\270\350\211\263/20241206\347\254\224\350\256\2609--\344\275\234\344\270\232iLnq\346\237\245\350\257\242\345\222\214Lambda\350\241\250\350\276\276\345\274\217.md" "b/\350\256\270\350\211\263/20241206\347\254\224\350\256\2609--\344\275\234\344\270\232iLnq\346\237\245\350\257\242\345\222\214Lambda\350\241\250\350\276\276\345\274\217.md" new file mode 100644 index 0000000..83989d5 --- /dev/null +++ "b/\350\256\270\350\211\263/20241206\347\254\224\350\256\2609--\344\275\234\344\270\232iLnq\346\237\245\350\257\242\345\222\214Lambda\350\241\250\350\276\276\345\274\217.md" @@ -0,0 +1,246 @@ +## 作业 +1. +```js + + // 1.找出数组中等于5的元素。 + public dynamic One(){ + int[] numbers = { 1, 2, 3, 4, 5, 6 }; + var num=numbers.Where(x=>x==5); + return num; + } + // 2.找出数组中在2到8之间的元素。 + public dynamic Two(){ + int[] numbers = { 1, 2, 3, 4, 5, 6 }; + var num=numbers.Where(x=>x>2 && x<8); + return num; + } + // 3.将数组中的每个数字乘以2 + public dynamic Three(){ + int[] numbers = { 1, 2, 3, 4, 5, 6 }; + var num=numbers.Select(x=>x*2); + return num; + } + // 4.找出所有名字以"王"开头的学生 + public dynamic Four(){ + List students = new List + { + new Student {Id=1, Name = "王有才", Age = 21 }, + new Student {Id=2, Name = "王中王", Age = 22 }, + new Student {Id=3, Name = "张语嫣", Age = 23 }, + new Student {Id=4, Name = "詹宇航", Age = 35 }, + new Student {Id=5, Name = "郑雨良", Age = 26 }, + }; + var stu=students.Where(x=>x.Name.StartsWith('王')); + return stu; + } + // 5.找出所有年龄大于20岁的学生,并按年龄降序排列。 + public dynamic Five(){ + List students = new List + { + new Student {Id=1, Name = "王有才", Age = 21 }, + new Student {Id=2, Name = "罗婷", Age = 21 }, + new Student {Id=3, Name = "王中王", Age = 22 }, + new Student {Id=4, Name = "李子柒", Age = 22 }, + new Student {Id=5, Name = "张语嫣", Age = 23 }, + new Student {Id=6, Name = "詹宇航", Age = 35 }, + new Student {Id=7, Name = "郑雨良", Age = 26 }, + new Student {Id=8, Name = "欧文", Age = 26 }, + }; + var num=students.Where(x=>x.Age >20).OrderByDescending(x=>x.Age); + return num; + } + // 6.找出数组中所有不重复的数字 + public dynamic Six(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Distinct(); + return num; + } + + // 7.找出数组中第一个大于3的元素 + public dynamic Seven(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.First(x=> x>3); + return num; + } + + // 8.找出数组中最后一个小于7的元素。 + public dynamic Eight(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.LastOrDefault(x=> x<7); + return num; + } + + // 9.查询元素是否存在 检查数组中是否存在大于10的元素 + public dynamic Nine(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Any(x=>x>10); + return num; + } + + // 10.查询元素的计数 计算数组中大于5的元素数量 + public dynamic Ten(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Count(x=>x>5); + return num; + } + + // 11.查询元素的总和 计算数组中所有元素的总和。 + public dynamic One1(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Sum(); + return num; + } + + // 12.查询元素的最大值 找出数组中的最大值 + public dynamic Two1(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Max(); + return num; + } + + // 13.查询元素的最小值 找出数组中的最小值 + public dynamic Three1(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Min(); + return num; + } + + // 14.查询元素的平均值 计算数组中所有元素的平均值 + public dynamic Four1(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Average(); + return num; + } + + // 15.查询特定条件的元素 找出数组中能被3整除的元素 + public dynamic Five1(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Where(x=>x%3==0); + return num; + } + + // 16.找出所有学生的姓名和年龄。 + public dynamic Six1(){ + List students = new List +{ + new Student {Id=1, Name = "王有才", Age = 21 }, + new Student {Id=2, Name = "罗婷", Age = 21 }, + new Student {Id=3, Name = "王中王", Age = 22 }, + new Student {Id=4, Name = "李子柒", Age = 22 }, + new Student {Id=5, Name = "张语嫣", Age = 23 }, + new Student {Id=6, Name = "詹宇航", Age = 35 }, + new Student {Id=7, Name = "郑雨良", Age = 26 }, + new Student {Id=8, Name = "欧文", Age = 26 }, +}; + var num=students.Select(x=>new{x.Name,x.Age}); + return num; + } + // 17.查询并分组 按年龄分组学生,并计算每个年龄组的学生数量。 + public dynamic Seven1(){ + List students = new List +{ + new Student {Id=1, Name = "王有才", Age = 21 }, + new Student {Id=2, Name = "罗婷", Age = 21 }, + new Student {Id=3, Name = "王中王", Age = 22 }, + new Student {Id=4, Name = "李子柒", Age = 22 }, + new Student {Id=5, Name = "张语嫣", Age = 23 }, + new Student {Id=6, Name = "詹宇航", Age = 35 }, + new Student {Id=7, Name = "郑雨良", Age = 26 }, + new Student {Id=8, Name = "欧文", Age = 26 }, +}; + var num=students.GroupBy(x => x.Age).Select(s => new { Age = s.Key, Count = s.Count() }); + return num; + } + + // 18.查询并联结 联结学生和课程表,找出每个学生的所有课程。 + public dynamic Eight1(){ + List students = new List + { + new Student {Id=1, Name = "王有才", Age = 21 }, + new Student {Id=2, Name = "罗婷", Age = 21 }, + new Student {Id=3, Name = "王中王", Age = 22 }, + new Student {Id=4, Name = "李子柒", Age = 22 }, + new Student {Id=5, Name = "张语嫣", Age = 23 }, + new Student {Id=6, Name = "詹宇航", Age = 35 }, + new Student {Id=7, Name = "郑雨良", Age = 26 }, + new Student {Id=8, Name = "欧文", Age = 26 }, + }; + List courses=new List + { + new Course{StudentId=1,CourseName="英语"}, + new Course{StudentId=1,CourseName="数学"}, + new Course{StudentId=2,CourseName="语文"}, + new Course{StudentId=3,CourseName="物理"}, + new Course{StudentId=4,CourseName="化学"}, + new Course{StudentId=4,CourseName="生物"}, + new Course{StudentId=4,CourseName="语文"}, + }; + var num = students.Join(courses, s => s.Id, c => c.StudentId,(students, courses) => new { studentName = students.Name, courses = courses.CourseName }); + return num; + } + // 19.查询并反转 反转数组中的元素顺序 + public dynamic Nine1(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num =numbers.Reverse(); + return num; + } + + // 20. 查询并填充 找出数组中第一个大于2的元素,并用它填充后面的所有位置 + public dynamic Ten1(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num =numbers.First(x=> x>2); + return num; + } + + // 21.查询并排除 从数组中排除所有小于5的元素。 + public dynamic One2(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num =numbers.Where(x=>x>5); + return num; + } + + // 22.查询并填充默认值 如果数组中存在null值,用默认值0替换。 + public dynamic Two2(){ + int?[] nullableNumbers = { 1, null, 3, null, 5 }; + var num=nullableNumbers.Select(n=>n ??0); + return num; + } + + // 23.查询并转换类型 将字符串数组转换为整数数组。 + public dynamic Three3(){ + string[] stringNumbers = { "1", "2", "3", "4" }; + var num=stringNumbers.Select(s => int.Parse(s)); + return num; + } + + // 24.查询并使用OfType过滤 从对象数组中过滤出字符串类型的元素。 + public dynamic Four2(){ + object[] objects = { "String", 123, "Another String", 456 }; + var result = objects.OfType().ToList(); + return result; + } + + // 25.查询并使用Zip合并 合并两个数组,并创建一个包含元素对的新数组。 + public dynamic Five2(){ + int[] numbers1 = { 1, 2, 3 }; + int[] numbers2 = { 4, 5, 6 }; + var num=numbers1.Zip(numbers2,(x,y)=> x + " " + y); + return num; + } + + + // 28.查询并使用Take限制数量 从数组中取出前5个元素。 + public dynamic Eight2(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Take(5); + return num; + } + + // 29.查询并使用Skip跳过元素 跳过数组中的前3个元素,然后取出剩余的元素。 + public dynamic Nine2(){ + int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; + var num=numbers.Skip(3); + return num; + } + +``` \ No newline at end of file -- Gitee