diff --git "a/\351\202\223\345\256\227\346\235\203/20241114-\346\226\207\344\273\266\347\273\223\346\236\204.md" "b/\351\202\223\345\256\227\346\235\203/20241114-\346\226\207\344\273\266\347\273\223\346\236\204.md" new file mode 100644 index 0000000000000000000000000000000000000000..7da6751d2d0c360dec524843d1ccdecdf4359ad4 --- /dev/null +++ "b/\351\202\223\345\256\227\346\235\203/20241114-\346\226\207\344\273\266\347\273\223\346\236\204.md" @@ -0,0 +1,10 @@ +# 基本结构 + 文件夹 + 解决方案(创建语法 : dotnet new sln -n 解决方案名) + src文件夹(里面的子级文件统称项目) + mvc项目(一个 | 创建语法 : dotnet new mve -o mvc项目名) + 类库(多个 | 创建语法 : dotnet new calsslib -o 类库名) + 项目绑定 + dotnet sln add 绑定项目的路径 +## 练习 + \ No newline at end of file diff --git "a/\351\202\223\345\256\227\346\235\203/20241119-\346\216\247\345\210\266\345\231\2501.md" "b/\351\202\223\345\256\227\346\235\203/20241119-\346\216\247\345\210\266\345\231\2501.md" new file mode 100644 index 0000000000000000000000000000000000000000..fe7da62a79ccb6ab0c6a31f39d35b91ac279c42d --- /dev/null +++ "b/\351\202\223\345\256\227\346\235\203/20241119-\346\216\247\345\210\266\345\231\2501.md" @@ -0,0 +1,38 @@ + +# 练习 + +创建一个控制台项目,没有任何选项,体会项目名称和什么有关系 + + +创建一个控制项目,项目名称Blog + + +创建一个控制台项目,输出到Blog目录 + + +创建一个MVC项目,指定项目名称 + + +创建一个MVC项目,指定输出目录 + + +创建一个带解决方案,其下有一个MVC项目,3个类库项目的“综合项目” + + +创建一个项目,在默认控制器(Home)下,新增一个Action方法,名为Ok,同时为其创建对应视图以显示这个视图 + + +创建一个项目,创建一个新的控制器,名为Blogs,新的控制器拥有一个名为Index的Action,该方法返回一个视图,视图显示“神级预判” + + +给第8题的新控制,添加一个新的Action,名为Music,不接受任何参数,并返回对应的视图,视图显示“顶级打野” + + +给第8题的新控制器,新增一个Action,名为List,不接受任何参数,并返回对应视图,视图显示一个经典CRUD界面 + + +新增一个控制器,名为Products,该控制器具有一个名为Edit的Action,这个Action接受一个int类型的参数id,显示这个id + + +在11题的新控制器中,新增一个名为Create的Action,该Action接受一个类型为Students(有姓名、年龄、体长属性)的参数,并展示该参数的姓名属性 + \ No newline at end of file diff --git "a/\351\202\223\345\256\227\346\235\203/20241121-\346\216\247\345\210\266\345\231\2502.md" "b/\351\202\223\345\256\227\346\235\203/20241121-\346\216\247\345\210\266\345\231\2502.md" new file mode 100644 index 0000000000000000000000000000000000000000..fd8c2ed9ff06db7a2d89387f8a39a4b8d3e793ec --- /dev/null +++ "b/\351\202\223\345\256\227\346\235\203/20241121-\346\216\247\345\210\266\345\231\2502.md" @@ -0,0 +1,8 @@ +# 控制器 +方式1--地址传参 +
+url/值 接收一般为id,可以在路由更改。 + +方式2--[FromBody]传参 +
+定义一个类接收 类名CreateDto 定义属性 访问前提: 类前面加请求方式[HttpPost] 参数前面加[FromBody] \ No newline at end of file diff --git "a/\351\202\223\345\256\227\346\235\203/20241122-\350\277\224\345\233\236\345\200\274.md" "b/\351\202\223\345\256\227\346\235\203/20241122-\350\277\224\345\233\236\345\200\274.md" new file mode 100644 index 0000000000000000000000000000000000000000..49cefeab561008b7d7a0efebb53df23327bbd9bc --- /dev/null +++ "b/\351\202\223\345\256\227\346\235\203/20241122-\350\277\224\345\233\236\345\200\274.md" @@ -0,0 +1,41 @@ +# 返回值 +一般数据类型 +
+IActionResult类型(接口) +
+ActionResult类型(接口加一般数据类型) +
+特定于格式的操作结果 +
+Poco(普通旧CLR对象) + +## 作业 + +简单参数传递 在一个叫Blog控制器中,定义一个叫Index的Action,并且传递一个int类型的值,id为变量名 + +简单参数传递 在一个叫Blog控制器中,定义一个叫Index_2的Action,并且传递一个string类型的值,id为变量名 + +简单参数传递 在一个叫Blog控制器中,定义一个叫Index_3的Action,并且传递一个string类型的值,name为变量名 + +复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create的Action,并且传递一个BlogCreateDto类型的值,blogCreateDto为变量名 + +复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create_1的Action,并且传递一个Products类型的值,productCreateDto为变量名 + +复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create_2的Action,并且传递一个Students类型的值,studentCreateDto为变量名 + + +生成一个随机整数,范围[0,100],注意是否包含 + +生成一个随机整数,范围(0,100],注意是否包含 + +生成10个随机整数,范围[5,80],注意是否包含 + +定义一个字符串,字符串中有100个中文字符,需要从中随机取1个字符串 + +定义一个字符串,字符串中有100个中文字符,需要从中随机取5-50个字符,组成新的字符 + +定义2个字符串,第一个字符串中放百家姓,第二个字符串中放中文字符,要求从第一个字符串随机取得一个姓,再从第二个字符串中随机获得1到2个字符组成新字符串,和第一个字符串取得的姓组成一个姓名 + +利用以上方法,随机生成100个BlogCreateDto类型(有Title、Author、Content属性)的对象,其中的内容都是随机生成且长度不定,并将其渲染到视图 + + \ No newline at end of file diff --git "a/\351\202\223\345\256\227\346\235\203/20241126-\346\255\243\345\217\215\344\273\243\347\220\206.md" "b/\351\202\223\345\256\227\346\235\203/20241126-\346\255\243\345\217\215\344\273\243\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..17e1efe30e753bd151e67f9b429b0303ecc13d57 --- /dev/null +++ "b/\351\202\223\345\256\227\346\235\203/20241126-\346\255\243\345\217\215\344\273\243\347\220\206.md" @@ -0,0 +1,8 @@ +## 正向代理 + + +pc 通过找一个代理服务器 让代理服务器去访问 web服务器 + +## 反向代理 + +web服务器设置一个代理服务器让pc端 通过访问 代理服务器 访问 web服务器 \ No newline at end of file diff --git "a/\351\202\223\345\256\227\346\235\203/20241128-\350\257\225\345\233\276.md" "b/\351\202\223\345\256\227\346\235\203/20241128-\350\257\225\345\233\276.md" new file mode 100644 index 0000000000000000000000000000000000000000..4a2b45edd20a395139dd7fb043e9d3892df80b6f --- /dev/null +++ "b/\351\202\223\345\256\227\346\235\203/20241128-\350\257\225\345\233\276.md" @@ -0,0 +1,13 @@ +# 视图定义属性 +定义: @{ 属性(键值对) } 调用: @键 + +## 接收view +@model 命名空间.类名 @Model.键 + +## 练习 + + + + + + \ No newline at end of file diff --git "a/\351\202\223\345\256\227\346\235\203/20241205-\350\241\250\345\215\225.md" "b/\351\202\223\345\256\227\346\235\203/20241205-\350\241\250\345\215\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..443e282aa1a60bd38ce686190d00d6051c58a552 --- /dev/null +++ "b/\351\202\223\345\256\227\346\235\203/20241205-\350\241\250\345\215\225.md" @@ -0,0 +1,284 @@ +# 基础练习 +1.查询特定元素 找出数组中等于5的元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6 }; +```c# + var result = numbers.Where(n => n == 5).ToArray(); + + Console.WriteLine("等于5的元素:"); + foreach (var number in result) + { + Console.WriteLine(number); + } +``` +2.查询特定范围的元素 找出数组中在2到8之间的元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6 }; +```c# +var result = numbers.Where(n => n >= 2 && n <= 8).ToArray(); + +``` +3.查询并转换元素 将数组中的每个数字乘以2。 + +int[] numbers = { 1, 2, 3, 4, 5, 6 }; +```c# + var result = numbers.Select(n => n * 2).ToArray(); +``` +4.查询特定属性的对象 找出所有名字以"王"开头的学生。 + +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 }, +}; +```c# +var result = students.Where(s => s.Name.StartsWith("王")).ToList(); +``` +5.查询并排序 找出所有年龄大于20岁的学生,并按年龄降序排列。 + + 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 }, +}; +```c# + var result = students.Where(s => s.Age > 20) + .OrderByDescending(s => s.Age) + .ToList(); +``` +6.查询并去重 找出数组中所有不重复的数字。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# + var distinctNumbers = numbers.Distinct().ToArray(); +``` +7.查询第一个元素 找出数组中第一个大于3的元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# + var firstGreaterThanThree = numbers.FirstOrDefault(n => n > 3); +``` +8.查询最后一个元素 找出数组中最后一个小于7的元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# + var lastLessThanSeven = numbers.LastOrDefault(n => n < 7); +``` +9.查询元素是否存在 检查数组中是否存在大于10的元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# + bool existsGreaterThanTen = numbers.Any(n => n > 10); +``` +10.查询元素的计数 计算数组中大于5的元素数量。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# +int countGreaterThanFive = numbers.Count(n => n > 5); +``` +11.查询元素的总和 计算数组中所有元素的总和。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# + int sum = numbers.Sum(); +``` +12.查询元素的最大值 找出数组中的最大值。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# +int maxValue = numbers.Max(); +``` +13.查询元素的最小值 找出数组中的最小值。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# +int minValue = numbers.Min(); +``` +14.查询元素的平均值 计算数组中所有元素的平均值。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# + double average = numbers.Average(); +``` +15.查询特定条件的元素 找出数组中能被3整除的元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# + var divisibleByThree = numbers.Where(n => n % 3 == 0).ToArray(); +``` +# 中级练习 +16.查询并选择特定属性 找出所有学生的姓名和年龄。 + +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 }, +}; +```c# +var result = students.Select(s => new { s.Name, s.Age }).ToList(); + foreach (var student in result) + { + Console.WriteLine($"姓名: {student.Name}, 年龄: {student.Age}"); + } +``` +17.查询并分组 按年龄分组学生,并计算每个年龄组的学生数量。 + +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 }, +}; +```c# +var groupedStudents = students.GroupBy(s => s.Age) + .Select(g => new { Age = g.Key, Count = g.Count() }) + .ToList(); +``` +18.查询并联结 联结学生和课程表,找出每个学生的所有课程。 + +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="语文"}, +}; +```c# +// 联结学生和课程 + var studentCourses = from student in students + join course in courses on student.Id equals course.StudentId into courseGroup + select new + { + StudentName = student.Name, + Courses = courseGroup.Select(c => c.CourseName).ToList() + }; + + // 输出结果 + foreach (var sc in studentCourses) + { + Console.WriteLine($"学生: {sc.StudentName}, 课程: {string.Join(", ", sc.Courses)}"); + } +``` +19.查询并反转 反转数组中的元素顺序。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# +var reversedNumbers = numbers.Reverse().ToArray(); +``` +20.查询并填充 找出数组中第一个大于2的元素,并用它填充后面的所有位置。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# +// 找到第一个大于2的元素 + int? firstGreaterThanTwo = numbers.FirstOrDefault(n => n > 2); + + // 用找到的元素填充后面的所有位置 + for (int i = 0; i < numbers.Length; i++) + { + if (firstGreaterThanTwo.HasValue && i >= Array.IndexOf(numbers, firstGreaterThanTwo)) + { + numbers[i] = firstGreaterThanTwo.Value; + } + } + + Console.WriteLine("填充后的数组:"); + Console.WriteLine(string.Join(", ", numbers)); +``` +21.查询并排除 从数组中排除所有小于5的元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# + var filteredNumbers = numbers.Where(n => n >= 5).ToArray(); + + Console.WriteLine("排除小于5的元素后的数组:"); + Console.WriteLine(string.Join(", ", filteredNumbers)); +``` +22.查询并填充默认值 如果数组中存在null值,用默认值0替换。 + +int?[] nullableNumbers = { 1, null, 3, null, 5 }; +```c# + var filledNumbers = nullableNumbers.Select(n => n ?? 0).ToArray(); +``` +23.查询并转换类型 将字符串数组转换为整数数组。 + +string[] stringNumbers = { "1", "2", "3", "4" }; +```c# + int[] intNumbers = stringNumbers.Select(int.Parse).ToArray(); +``` +24.查询并使用OfType过滤 从对象数组中过滤出字符串类型的元素。 + +object[] objects = { "String", 123, "Another String", 456 }; +var result = objects.OfType().ToList(); +```c# +var result = objects.OfType().ToList(); +``` +# 高级练习 +25.查询并使用Zip合并 合并两个数组,并创建一个包含元素对的新数组。 + +int[] numbers1 = { 1, 2, 3 }; +int[] numbers2 = { 4, 5, 6 }; +```c# +// 使用 Zip 方法合并两个数组 + var zipped = numbers1.Zip(numbers2, (n1, n2) => new { n1, n2 }).ToArray(); + + // 输出合并后的数组 + Console.WriteLine("合并后的数组:"); + foreach (var pair in zipped) + { + Console.WriteLine($"({pair.n1}, {pair.n2})"); + } +``` +26.查询并使用Range生成 生成一个包含1到10的整数数组。 +```c# +int[] numbers = Enumerable.Range(1,10).ToArray(); +``` +27.查询并使用Repeat重复 重复一个元素多次,创建一个新数组。 +```c# +int[] numbers = Enumerable.Repeat(1,10).ToArray(); +``` +28.查询并使用Take限制数量 从数组中取出前5个元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +```c# +var takenNumbers = numbers.Take(5).ToArray(); +``` +29.查询并使用Skip跳过元素 跳过数组中的前3个元素,然后取出剩余的元素。 + +int[] numbers = { 1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 } +```c# + var skippedNumbers = numbers.Skip(3).ToArray(); +``` \ No newline at end of file