C# 零基础到精通教程 - 第六章:方法——让代码“模块化“

news2026/5/20 23:47:38
6.1 为什么需要方法6.1.1 没有方法的问题csharp// 没有方法代码重复、臃肿、难以维护 static void Main() { // 第一次计算两个数的和 int a1 10, b1 20; int sum1 a1 b1; Console.WriteLine(${a1} {b1} {sum1}); // 第二次计算两个数的和 int a2 15, b2 25; int sum2 a2 b2; Console.WriteLine(${a2} {b2} {sum2}); // 第三次... // 每次都要重复写同样的代码 }6.1.2 有方法的解决方案csharp// 定义一个方法封装加法并输出的功能 static void AddAndPrint(int a, int b) { int sum a b; Console.WriteLine(${a} {b} {sum}); } static void Main() { AddAndPrint(10, 20); // 一行代码解决问题 AddAndPrint(15, 25); AddAndPrint(100, 200); }6.1.3 方法的定义方法 一个具有名称的代码块用于执行特定任务text方法的比喻 ┌─────────────────────────────────────────────────────────┐ │ 餐厅的做菜流程 │ ├─────────────────────────────────────────────────────────┤ │ │ │ 点菜单参数 菜品返回值 │ │ ↓ ↑ │ │ ┌─────────────────────────────────────┐ │ │ │ 做菜方法 │ │ │ │ 1. 洗菜 │ │ │ │ 2. 切菜 │ │ │ │ 3. 炒菜 │ │ │ │ 4. 调味 │ │ │ │ 5. 装盘 │ │ │ └─────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────┘6.2 方法的声明和调用6.2.1 方法的基本语法csharp// 语法 [访问修饰符] [static] 返回值类型 方法名(参数列表) { // 方法体执行的代码 return 返回值; // 如果返回值类型不是 void必须有 return } // 最简单的无参无返回值方法 static void SayHello() { Console.WriteLine(Hello!); } // 有参数无返回值 static void Greet(string name) { Console.WriteLine($你好{name}); } // 有参数有返回值 static int Add(int a, int b) { return a b; }6.2.2 方法的各个部分csharp// 完整示例 static int CalculateSum(int start, int end) // ↑ ↑ ↑ ↑ ↑ // 修饰符 返回值类型 方法名 参数1 参数2 { int sum 0; for (int i start; i end; i) { sum i; } return sum; // 返回计算结果 }各部分详解部分说明示例static静态方法可以直接通过类名调用static返回值类型方法返回什么类型的数据如果不返回用voidint,string,double,void方法名标识方法使用 PascalCase 命名规范CalculateSum,GetName参数列表传入方法的数据可以有多个用逗号分隔(int a, string b)方法体花括号内的代码{ ... }return返回值并结束方法return sum;6.2.3 调用方法csharpstatic void Main() { // 调用无返回值方法 SayHello(); // 调用有参数方法 Greet(张三); // 调用有返回值方法 int result Add(5, 3); Console.WriteLine($5 3 {result}); // 也可以直接使用返回值 Console.WriteLine($10 20 {Add(10, 20)}); }6.2.4 方法的执行流程textMain 方法 ┌─────────────────────────────────────────┐ │ int result Add(5, 3); │ │ │ │ │ │ 调用 Add 方法 │ │ ↓ │ └───────┼─────────────────────────────────┘ │ ↓ ┌─────────────────────────────────────────┐ │ static int Add(int a, int b) │ │ { │ │ // a 5, b 3 │ │ int sum a b; // sum 8 │ │ return sum; // 返回 8 │ │ } │ └───────┬─────────────────────────────────┘ │ │ 返回值 8 ↓ ┌─────────────────────────────────────────┐ │ int result 8; │ └─────────────────────────────────────────┘6.3 方法的参数6.3.1 参数的基本使用csharp// 单个参数 static void PrintSquare(int number) { Console.WriteLine(${number} 的平方是 {number * number}); } // 多个参数 static double CalculateRectangleArea(double width, double height) { return width * height; } // 调用 PrintSquare(5); // 输出5 的平方是 25 double area CalculateRectangleArea(10.5, 20.3);6.3.2 参数的传递机制值类型参数传递的是值的副本方法内修改不影响原变量csharpstatic void ChangeValue(int x) { x 100; // 修改的是副本 Console.WriteLine($方法内部x {x}); } static void Main() { int a 10; ChangeValue(a); Console.WriteLine($方法外部a {a}); } // 输出 // 方法内部x 100 // 方法外部a 10 ← 没有改变6.3.3 ref 参数引用传递使用 ref 关键字传递的是变量的引用方法内修改会影响原变量csharpstatic void ChangeValueByRef(ref int x) { x 100; // 修改的是原变量 Console.WriteLine($方法内部x {x}); } static void Main() { int a 10; ChangeValueByRef(ref a); // 调用时也要写 ref Console.WriteLine($方法外部a {a}); } // 输出 // 方法内部x 100 // 方法外部a 100 ← 被改变了6.3.4 out 参数输出参数out 参数用于从方法返回多个值调用前不需要初始化csharp// 返回多个值商和余数 static void Divide(int dividend, int divisor, out int quotient, out int remainder) { quotient dividend / divisor; remainder dividend % divisor; } // 经典的 TryParse 模式 static bool TryParseToInt(string input, out int result) { try { result Convert.ToInt32(input); return true; } catch { result 0; return false; } } static void Main() { // 使用 out 参数 int q, r; Divide(17, 5, out q, out r); Console.WriteLine($17 ÷ 5 {q} 余 {r}); // 17 ÷ 5 3 余 2 // TryParse 模式 string input 123abc; if (TryParseToInt(input, out int number)) { Console.WriteLine($转换成功{number}); } else { Console.WriteLine(转换失败); } }6.3.5 ref vs out 对比特点refout传入前是否需要初始化需要不需要方法内是否必须赋值不必必须返回前要赋值用途修改传入的变量返回额外的值调用时写法ref关键字out关键字csharp// ref传入前必须初始化 int refValue 10; // 必须初始化 MethodWithRef(ref refValue); // out传入前不需要初始化 int outValue; // 可以不初始化 MethodWithOut(out outValue); // 方法内必须赋值6.3.6 默认参数可选参数csharp// 带默认值的参数必须放在参数列表的最后 static void Greet(string name, string greeting 你好) { Console.WriteLine(${greeting}{name}); } static void Main() { Greet(张三); // 使用默认值你好张三 Greet(李四, 晚上好); // 使用传入值晚上好李四 }6.3.7 命名参数调用时可以指定参数名称不按位置传递csharpstatic void PrintPersonInfo(string name, int age, string city) { Console.WriteLine($姓名{name}年龄{age}城市{city}); } static void Main() { // 位置参数按顺序 PrintPersonInfo(张三, 25, 北京); // 命名参数可以不按顺序 PrintPersonInfo(city: 上海, name: 李四, age: 30); // 混合使用位置参数必须在命名参数之前 PrintPersonInfo(王五, city: 广州, age: 28); }6.4 方法的返回值6.4.1 返回值的基本使用csharp// 返回 int 类型 static int GetMax(int a, int b) { if (a b) return a; else return b; } // 返回 string 类型 static string GetGreeting(string name) { return $你好{name}欢迎回来。; } // 返回 bool 类型 static bool IsAdult(int age) { return age 18; } // 调用 int max GetMax(10, 20); string greeting GetGreeting(张三); bool canVote IsAdult(18);6.4.2 void 方法无返回值csharp// void 表示不返回任何值 static void PrintBanner() { Console.WriteLine(******************); Console.WriteLine(* 欢迎来到C#世界 *); Console.WriteLine(******************); } // 调用 PrintBanner(); // void 方法也可以使用 return但不能返回值用于提前结束 static void PrintNumbers(int max) { if (max 0) { Console.WriteLine(参数无效); return; // 提前结束 } for (int i 1; i max; i) { Console.Write(i ); } Console.WriteLine(); }6.4.3 返回数组csharp// 返回一个整型数组 static int[] GenerateRandomArray(int length, int min, int max) { Random random new Random(); int[] array new int[length]; for (int i 0; i length; i) { array[i] random.Next(min, max 1); } return array; } // 调用 int[] numbers GenerateRandomArray(10, 1, 100); Console.WriteLine($随机数组{string.Join(, , numbers)});6.4.4 返回多个值使用元组C# 7.0 支持元组语法可以轻松返回多个值csharp// 使用元组返回多个值 static (int sum, int count, double average) CalculateStats(int[] numbers) { int sum 0; foreach (int num in numbers) { sum num; } int count numbers.Length; double average count 0 ? (double)sum / count : 0; return (sum, count, average); } static void Main() { int[] scores { 85, 92, 78, 90, 88 }; // 接收元组返回值 (int total, int num, double avg) CalculateStats(scores); Console.WriteLine($总数{total}); Console.WriteLine($个数{num}); Console.WriteLine($平均{avg:F2}); // 也可以单独接收 var stats CalculateStats(scores); Console.WriteLine($总和{stats.sum}); Console.WriteLine($平均{stats.average:F2}); }6.5 方法的重载6.5.1 什么是方法重载同一个类中多个方法可以使用相同的名字只要参数列表不同csharp// 同一个方法名 Add不同的参数 static int Add(int a, int b) { return a b; } static double Add(double a, double b) { return a b; } static int Add(int a, int b, int c) { return a b c; } static string Add(string a, string b) { return a b; } // 调用时编译器根据传入的参数自动选择合适的方法 static void Main() { Console.WriteLine(Add(5, 3)); // 调用 int Add(int, int) Console.WriteLine(Add(5.5, 3.2)); // 调用 double Add(double, double) Console.WriteLine(Add(1, 2, 3)); // 调用 int Add(int, int, int) Console.WriteLine(Add(Hello, World)); // 调用 string Add(string, string) }6.5.2 重载的规则可以重载的情况csharp// 1. 参数个数不同 void Print(int a) { } void Print(int a, int b) { } // 2. 参数类型不同 void Print(int a) { } void Print(string a) { } // 3. 参数顺序不同 void Print(int a, string b) { } void Print(string a, int b) { }不能重载的情况csharp// ❌ 只有返回值类型不同不能重载 int GetValue() { return 0; } string GetValue() { return ; } // 编译错误 // ❌ 只有参数名称不同不能重载 void Print(int x) { } void Print(int y) { } // 编译错误 // ❌ 只有 ref/out 区别不能重载 void Process(ref int x) { } void Process(out int x) { } // 编译错误6.5.3 重载的实际应用Console.WriteLinecsharp// Console.WriteLine 有 19 个重载版本 Console.WriteLine(); // 输出空行 Console.WriteLine(Hello); // 输出字符串 Console.WriteLine(123); // 输出整数 Console.WriteLine(3.14); // 输出小数 Console.WriteLine(true); // 输出布尔值 Console.WriteLine({0} {1} {2}, 1, 2, 3); // 格式化输出6.6 方法的递归6.6.1 什么是递归递归 方法调用自身csharp// 递归的经典例子阶乘 // n! n × (n-1) × (n-2) × ... × 1 static int Factorial(int n) { // 终止条件基础情况 if (n 1) return 1; // 递归调用n! n × (n-1)! return n * Factorial(n - 1); } // 执行过程Factorial(5) // Factorial(5) 5 × Factorial(4) // Factorial(4) 4 × Factorial(3) // Factorial(3) 3 × Factorial(2) // Factorial(2) 2 × Factorial(1) // Factorial(1) 1 // 然后逐层返回2×12, 3×26, 4×624, 5×241206.6.2 递归的必要条件csharp// 递归必须满足 // 1. 有终止条件防止无限递归 // 2. 每次递归调用都向终止条件靠近 // ✅ 正确示例斐波那契数列 static int Fibonacci(int n) { if (n 1) return n; // 终止条件 return Fibonacci(n - 1) Fibonacci(n - 2); // 向终止条件靠近 } // ❌ 错误示例没有终止条件 static void InfiniteRecursion() { Console.WriteLine(无限递归); InfiniteRecursion(); // 栈溢出 }6.6.3 递归的应用场景csharp// 1. 遍历文件夹目录树 static void PrintDirectory(string path, int level 0) { string indent new string( , level * 2); Console.WriteLine(${indent} {Path.GetFileName(path)}); try { // 遍历子目录 foreach (string dir in Directory.GetDirectories(path)) { PrintDirectory(dir, level 1); } // 遍历文件 foreach (string file in Directory.GetFiles(path)) { Console.WriteLine(${indent} {Path.GetFileName(file)}); } } catch (UnauthorizedAccessException) { Console.WriteLine(${indent} [无权限]); } } // 2. 汉诺塔问题 static void Hanoi(int n, char from, char to, char helper) { if (n 1) { Console.WriteLine($移动盘子 1 从 {from} 到 {to}); return; } Hanoi(n - 1, from, helper, to); Console.WriteLine($移动盘子 {n} 从 {from} 到 {to}); Hanoi(n - 1, helper, to, from); }6.6.4 递归 vs 循环特点递归循环代码简洁性适合树形结构适合线性问题性能较差有函数调用开销较好内存使用多每次调用占用栈空间少风险可能栈溢出可能死循环可读性自然递归逻辑需要手动维护状态csharp// 递归代码简洁但性能差 static int SumRecursive(int n) { if (n 0) return 0; return n SumRecursive(n - 1); } // 循环性能好但需要手动控制 static int SumLoop(int n) { int sum 0; for (int i 1; i n; i) { sum i; } return sum; }6.7 局部函数C# 7.0在方法内部定义的方法只能在所在方法内部使用csharpstatic void ProcessData(int[] numbers) { // 局部函数 bool IsEven(int n) { return n % 2 0; } int Square(int n) { return n * n; } // 使用局部函数 foreach (int num in numbers) { if (IsEven(num)) { Console.WriteLine(${num} 是偶数平方是 {Square(num)}); } } } static void Main() { int[] data { 1, 2, 3, 4, 5 }; ProcessData(data); // IsEven(10); // ❌ 错误局部函数外部不可见 }局部函数的优势限制作用域只在需要的地方可见可以访问外部方法的局部变量适合递归比 lambda 表达式更清晰6.8 综合示例示例1数学工具类csharpusing System; class MathTools { // 判断是否为质数 static bool IsPrime(int number) { if (number 2) return false; if (number 2) return true; if (number % 2 0) return false; int limit (int)Math.Sqrt(number); for (int i 3; i limit; i 2) { if (number % i 0) return false; } return true; } // 获取最大公约数欧几里得算法 static int GCD(int a, int b) { while (b ! 0) { int temp b; b a % b; a temp; } return a; } // 获取最小公倍数 static int LCM(int a, int b) { return a * b / GCD(a, b); } // 判断是否为回文数 static bool IsPalindrome(int number) { string str number.ToString(); int left 0, right str.Length - 1; while (left right) { if (str[left] ! str[right]) return false; left; right--; } return true; } static void Main() { Console.WriteLine($17 是质数吗{IsPrime(17)}); Console.WriteLine($24 和 36 的最大公约数{GCD(24, 36)}); Console.WriteLine($24 和 36 的最小公倍数{LCM(24, 36)}); Console.WriteLine($12321 是回文数吗{IsPalindrome(12321)}); } }示例2学生管理系统的完整实现csharpusing System; class StudentManager { static string[] names new string[100]; static int[] scores new int[100]; static int studentCount 0; static void Main() { bool running true; while (running) { ShowMenu(); string choice Console.ReadLine(); switch (choice) { case 1: AddStudent(); break; case 2: ShowAllStudents(); break; case 3: ShowStatistics(); break; case 4: SearchStudent(); break; case 5: SortByScore(); break; case 6: running false; Console.WriteLine(感谢使用再见); break; default: Console.WriteLine(无效选择请重新输入); break; } if (running choice ! 6) { Console.WriteLine(\n按任意键继续...); Console.ReadKey(); } } } static void ShowMenu() { Console.Clear(); Console.WriteLine( 学生管理系统 ); Console.WriteLine(1. 添加学生); Console.WriteLine(2. 查看所有学生); Console.WriteLine(3. 统计信息); Console.WriteLine(4. 查找学生); Console.WriteLine(5. 按成绩排序); Console.WriteLine(6. 退出); Console.Write(请选择); } static void AddStudent() { if (studentCount names.Length) { Console.WriteLine(学生数量已达上限); return; } Console.Write(请输入学生姓名); string name Console.ReadLine(); Console.Write(请输入学生成绩); if (!int.TryParse(Console.ReadLine(), out int score)) { Console.WriteLine(成绩输入无效); return; } names[studentCount] name; scores[studentCount] score; studentCount; Console.WriteLine($成功添加学生{name}成绩{score}); } static void ShowAllStudents() { if (studentCount 0) { Console.WriteLine(暂无学生数据); return; } Console.WriteLine(\n所有学生列表); Console.WriteLine(序号\t姓名\t成绩); Console.WriteLine(-----------------); for (int i 0; i studentCount; i) { Console.WriteLine(${i 1}\t{names[i]}\t{scores[i]}); } } static void ShowStatistics() { if (studentCount 0) { Console.WriteLine(暂无学生数据); return; } int sum 0, max scores[0], min scores[0]; string maxName names[0], minName names[0]; int passCount 0, failCount 0; for (int i 0; i studentCount; i) { sum scores[i]; if (scores[i] max) { max scores[i]; maxName names[i]; } if (scores[i] min) { min scores[i]; minName names[i]; } if (scores[i] 60) passCount; else failCount; } double average (double)sum / studentCount; Console.WriteLine(\n 统计信息 ); Console.WriteLine($学生总数{studentCount}); Console.WriteLine($总分{sum}); Console.WriteLine($平均分{average:F2}); Console.WriteLine($最高分{max}{maxName}); Console.WriteLine($最低分{min}{minName}); Console.WriteLine($及格人数{passCount}及格率{(double)passCount / studentCount * 100:F1}%); Console.WriteLine($不及格人数{failCount}不及格率{(double)failCount / studentCount * 100:F1}%); // 成绩分布 int[] levelCount new int[5]; // A,B,C,D,F for (int i 0; i studentCount; i) { if (scores[i] 90) levelCount[0]; else if (scores[i] 80) levelCount[1]; else if (scores[i] 70) levelCount[2]; else if (scores[i] 60) levelCount[3]; else levelCount[4]; } Console.WriteLine(\n成绩分布); Console.WriteLine($A (90-100){levelCount[0]}人); Console.WriteLine($B (80-89){levelCount[1]}人); Console.WriteLine($C (70-79){levelCount[2]}人); Console.WriteLine($D (60-69){levelCount[3]}人); Console.WriteLine($F (60){levelCount[4]}人); } static void SearchStudent() { if (studentCount 0) { Console.WriteLine(暂无学生数据); return; } Console.Write(请输入要查找的学生姓名); string searchName Console.ReadLine(); bool found false; for (int i 0; i studentCount; i) { if (names[i].Equals(searchName, StringComparison.OrdinalIgnoreCase)) { Console.WriteLine($找到学生{names[i]}成绩{scores[i]}); found true; } } if (!found) { Console.WriteLine($未找到名为“{searchName}”的学生。); } } static void SortByScore() { if (studentCount 1) { ShowAllStudents(); return; } // 冒泡排序按成绩降序 for (int i 0; i studentCount - 1; i) { for (int j 0; j studentCount - i - 1; j) { if (scores[j] scores[j 1]) { // 交换成绩 int tempScore scores[j]; scores[j] scores[j 1]; scores[j 1] tempScore; // 同时交换姓名 string tempName names[j]; names[j] names[j 1]; names[j 1] tempName; } } } Console.WriteLine(\n已按成绩从高到低排序); ShowAllStudents(); } }示例3猜数字游戏方法版csharpusing System; class GuessNumberGame { static Random random new Random(); static int secretNumber; static int attempts; static int maxAttempts 10; static void Main() { bool playAgain true; while (playAgain) { InitializeGame(); PlayGame(); playAgain AskPlayAgain(); } Console.WriteLine(感谢游玩再见); } static void InitializeGame() { secretNumber random.Next(1, 101); attempts 0; Console.Clear(); Console.WriteLine( 猜数字游戏 ); Console.WriteLine($我已经想好了一个1-100之间的数字。); Console.WriteLine($你有{maxAttempts}次机会猜中它); Console.WriteLine(); } static void PlayGame() { bool guessed false; while (attempts maxAttempts !guessed) { int guess GetPlayerGuess(); attempts; guessed CheckGuess(guess); if (!guessed attempts maxAttempts) { GiveHint(guess); } } ShowResult(guessed); } static int GetPlayerGuess() { int guess; bool validInput false; do { Console.Write($请输入你的猜测剩余{maxAttempts - attempts}次机会); string input Console.ReadLine(); if (int.TryParse(input, out guess) guess 1 guess 100) { validInput true; } else { Console.WriteLine(请输入1-100之间的有效数字); } } while (!validInput); return guess; } static bool CheckGuess(int guess) { if (guess secretNumber) { Console.WriteLine($\n 恭喜你用了{attempts}次猜中了数字{secretNumber}); return true; } return false; } static void GiveHint(int guess) { if (guess secretNumber) { Console.WriteLine(太小了再试试更大的数字); } else { Console.WriteLine(太大了再试试更小的数字); } // 提供距离提示 int difference Math.Abs(secretNumber - guess); if (difference 5) { Console.WriteLine( 非常接近了); } else if (difference 10) { Console.WriteLine(⭐ 比较接近了); } } static void ShowResult(bool guessed) { if (guessed) { // 根据猜中次数给出评价 if (attempts 3) Console.WriteLine( 天才你是个猜数字高手); else if (attempts 7) Console.WriteLine( 不错哦继续加油); else Console.WriteLine( 恭喜下次可以尝试更快猜中); } else { Console.WriteLine($\n 很遗憾机会用完了); Console.WriteLine($正确答案是{secretNumber}); } } static bool AskPlayAgain() { Console.Write(\n是否继续游戏(y/n)); string response Console.ReadLine()?.ToLower(); return response y || response yes; } }6.9 常见错误与陷阱错误1返回值类型不匹配csharpstatic int GetNumber() { return 123; // ❌ 不能返回 string } static int GetNumber() { // 没有 return 语句 // ❌ 非 void 方法必须有 return }错误2方法内代码不可达csharpstatic void Test() { return; Console.WriteLine(这行永远不会执行); // ❌ 警告不可达代码 }错误3递归没有终止条件csharpstatic void EndlessRecursion() { EndlessRecursion(); // ❌ 栈溢出异常 }错误4ref/out 使用错误csharpstatic void Method(ref int x) { } int a; Method(ref a); // ❌ ref 参数必须初始化 static void Method2(out int x) { } int b 10; Method2(out b); // out 参数不要求初始化但初始值会被忽略6.10 本章总结方法设计原则原则说明单一职责一个方法只做一件事方法名有意义方法名应该清楚表达功能参数不要太多建议不超过5个参数代码不要过长建议不超过50行避免副作用方法应该只做名称所描述的事方法签名方法签名 方法名 参数类型和顺序不包括返回值类型csharpvoid Print(int a) // 签名Print(int) void Print(string s) // 签名Print(string) int Print(int a) // ❌ 与第一个冲突只有返回值不同本章核心知识点text方法 ├── 定义static 返回值类型 方法名(参数列表) ├── 调用方法名(参数) ├── 返回值return 值void 无返回值 ├── 参数传递 │ ├── 值传递默认 │ ├── ref引用传递双向 │ └── out输出参数单向 ├── 参数特性 │ ├── 默认参数 │ ├── 命名参数 │ └── params可变参数 ├── 重载同名不同参 └── 递归方法调用自身6.11 练习题基础题编写一个方法PrintRectangle(int width, int height)输出由*组成的矩形。编写方法bool IsEven(int number)判断一个数是否为偶数。编写方法double CircleArea(double radius)计算圆的面积。编写方法int Power(int base, int exponent)计算 base 的 exponent 次方不用 Math.Pow。应用题编写方法int[] GeneratePrimes(int max)返回不超过 max 的所有质数。编写方法string ReverseString(string input)返回反转

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2629760.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…