From 0c90bca6c019abb3fe16147c9e0e18773af75dfd Mon Sep 17 00:00:00 2001 From: nyaasuki Date: Sat, 14 Dec 2024 18:08:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=94=E8=BF=90=E7=AE=97=E5=92=8CIF=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HelloWorld.sln | 6 ++++ doif/App.config | 6 ++++ doif/Program.cs | 47 +++++++++++++++++++++++++++++ doif/Properties/AssemblyInfo.cs | 33 ++++++++++++++++++++ doif/doif.csproj | 53 +++++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 doif/App.config create mode 100644 doif/Program.cs create mode 100644 doif/Properties/AssemblyInfo.cs create mode 100644 doif/doif.csproj diff --git a/HelloWorld.sln b/HelloWorld.sln index cb78aa6..621c678 100644 --- a/HelloWorld.sln +++ b/HelloWorld.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "HelloWorld\He EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "intVariable", "intVariable\intVariable.csproj", "{E4F0A953-68EB-4231-AE4C-040E1A13747A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "doif", "doif\doif.csproj", "{D927AAFB-7F50-43BE-B3E1-62364060B642}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {E4F0A953-68EB-4231-AE4C-040E1A13747A}.Debug|Any CPU.Build.0 = Debug|Any CPU {E4F0A953-68EB-4231-AE4C-040E1A13747A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E4F0A953-68EB-4231-AE4C-040E1A13747A}.Release|Any CPU.Build.0 = Release|Any CPU + {D927AAFB-7F50-43BE-B3E1-62364060B642}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D927AAFB-7F50-43BE-B3E1-62364060B642}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D927AAFB-7F50-43BE-B3E1-62364060B642}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D927AAFB-7F50-43BE-B3E1-62364060B642}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/doif/App.config b/doif/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/doif/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/doif/Program.cs b/doif/Program.cs new file mode 100644 index 0000000..b01260c --- /dev/null +++ b/doif/Program.cs @@ -0,0 +1,47 @@ +using System; + +class LogicalAndDemo +{ + static void Main() + { + // 提示用户输入年龄 + Console.Write("请输入您的年龄: "); + string ageInput = Console.ReadLine(); + + // 尝试将输入转换为整数类型 + int age; + bool isValidAge = int.TryParse(ageInput, out age); + + // 提示用户是否同意条款 + Console.Write("您是否同意条款? (yes/no): "); + string agreement = Console.ReadLine(); + + // 判断用户是否同意条款(忽略大小写) + bool isAgreed = agreement.ToLower() == "yes"; + + /* + * 使用逻辑与运算符 `&&` 来检查所有条件是否都满足: + * 1. 年龄输入是否有效 + * 2. 用户是否同意条款 + * 3. 年龄是否在18到100岁之间 + * + * 只有当所有条件都为 true 时,才执行欢迎逻辑 + * 否则,执行拒绝逻辑 + */ + if (isValidAge && isAgreed && age >= 18 && age <= 100) + { + Console.WriteLine("欢迎加入!"); + } + else + { + Console.WriteLine("抱歉,您无法加入。"); + } + + /* + * 总结: + * - `&&` 是逻辑与运算符,用于布尔表达式的条件判断 + * - 具有短路行为,如果左边的表达式为 false,右边的表达式不会被评估 + * - 常用于需要所有条件都为 true 时才执行某些操作的场景 + */ + } +} diff --git a/doif/Properties/AssemblyInfo.cs b/doif/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9c7c4db --- /dev/null +++ b/doif/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("doif")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("doif")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("d927aafb-7f50-43be-b3e1-62364060b642")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/doif/doif.csproj b/doif/doif.csproj new file mode 100644 index 0000000..89a817d --- /dev/null +++ b/doif/doif.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {D927AAFB-7F50-43BE-B3E1-62364060B642} + Exe + doif + doif + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file