且运算和IF用例
This commit is contained in:
parent
de72242125
commit
0c90bca6c0
@ -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
|
||||
|
6
doif/App.config
Normal file
6
doif/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||
</startup>
|
||||
</configuration>
|
47
doif/Program.cs
Normal file
47
doif/Program.cs
Normal file
@ -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 时才执行某些操作的场景
|
||||
*/
|
||||
}
|
||||
}
|
33
doif/Properties/AssemblyInfo.cs
Normal file
33
doif/Properties/AssemblyInfo.cs
Normal file
@ -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")]
|
53
doif/doif.csproj
Normal file
53
doif/doif.csproj
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D927AAFB-7F50-43BE-B3E1-62364060B642}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>doif</RootNamespace>
|
||||
<AssemblyName>doif</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user