Synchronization of old projects

Part1
This commit is contained in:
2025-09-30 16:46:01 +08:00
parent 116b65164b
commit 4e1548abe2
167 changed files with 8668 additions and 43 deletions
+211
View File
@@ -0,0 +1,211 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36203.30
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test1", "test1\test1.csproj", "{B5D2D87D-A962-4B4D-8D55-913F4B5D2467}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson1注释和console", "Lesson1\Lesson1注释和console.csproj", "{38D8CC7A-769C-4DE9-9835-54916128D614}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson2变量", "Lesson2变量\Lesson2变量.csproj", "{2E255F6C-89D2-4ECE-AC3F-4903A5D23765}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson2变量练习", "Lesson2变量练习\Lesson2变量练习.csproj", "{6BDC7E93-4AE2-4FD5-BD04-65720EDF0897}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson4变量的命名规则", "Lesson4变量的命名规则\Lesson4变量的命名规则.csproj", "{12B6A100-ABDE-40E8-B6F0-6FA53A805D9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson5常量", "Lesson5常量\Lesson5常量.csproj", "{29321A63-B872-4C19-B9B2-AEBD90D21697}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson6转义字符", "Lesson6转义字符\Lesson6转义字符.csproj", "{536E2B30-EA7F-4D2F-AE45-B518B988253D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson7转义字符练习", "Lesson7转义字符练习\Lesson7转义字符练习.csproj", "{2925D024-47CC-4632-9CCE-DB7C2EE597CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson7隐式转换_类型转换", "Lesson7隐式转换_类型转换\Lesson7隐式转换_类型转换.csproj", "{D47510F0-704D-4BB6-B814-4E7C5FA7F6D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson8_显式转换", "Lesson8_显示转换\Lesson8_显式转换.csproj", "{DE655809-4BE0-46CE-A6AF-576B2AD80AB3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson8_显式转换练习", "Lesson8_显式转换联系\Lesson8_显式转换练习.csproj", "{C3B313DE-D643-42EE-BF8B-0197CBE0096B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson9_异常捕获", "Lesson9_异常捕获\Lesson9_异常捕获.csproj", "{96CB3658-80EE-4F20-9A1B-79D43C25DEDF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson9_捕获异常练习", "Lesson9_捕获异常联系\Lesson9_捕获异常练习.csproj", "{2B9B9029-A2B0-4EAF-8C3D-1840C23209C3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson10_算数运算符", "Lesson10_算数运算符\Lesson10_算数运算符.csproj", "{29A255F2-FFD0-4749-889A-C473BD8B1A01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson10_算数运算符练习", "Lesson10_算数运算符练习\Lesson10_算数运算符练习.csproj", "{31DA648B-6D43-491D-8F74-A88095D778E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson11_字符串拼接", "Lesson11_字符串拼接\Lesson11_字符串拼接.csproj", "{90AE5DB8-797B-4D1D-B9C8-931B9CB031CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson11_字符串拼接练习", "Lesson11_字符串拼接练习\Lesson11_字符串拼接练习.csproj", "{390F2AAE-DADB-4054-B168-C4060195924F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson12_条件运算符", "Lesson12_条件运算符\Lesson12_条件运算符.csproj", "{C09FCC0C-79AC-4B56-8AE1-9914E2D9E2B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson12_条件运算符练习", "Lesson12_条件运算符练习\Lesson12_条件运算符练习.csproj", "{B9E82214-EFF4-4060-998D-6A2FBB1BD09C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson13_ 逻辑运算符", "Lesson13_ 逻辑运算符\Lesson13_ 逻辑运算符.csproj", "{8C3FDC09-CC22-460A-AB0C-E25BD103C7CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson13_逻辑运算符练习", "Lesson13_逻辑运算符练习\Lesson13_逻辑运算符练习.csproj", "{8D709A42-B8AA-4427-91DE-C9959F93F1A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson14_位运算", "Lesson14_位运算\Lesson14_位运算.csproj", "{0FC71AB1-4975-41ED-8DDA-6743C6622614}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson14_位运算练习", "Lesson14_位运算练习\Lesson14_位运算练习.csproj", "{563D0FEB-699D-4B22-8187-07A53891FF78}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson15_三目运算符", "Lesson15_三目运算符\Lesson15_三目运算符.csproj", "{B33DAB08-87FA-4EC1-A78E-0E38D9021CA5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson15_三目运算符练习", "Lesson15_三目运算符练习\Lesson15_三目运算符练习.csproj", "{5A54CA20-4B7A-48D5-B975-16BD8A7529BC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson16_条件分支语句if", "Lesson16_if语句\Lesson16_条件分支语句if.csproj", "{E62F1255-E9C2-4738-B365-25BF5F6C6A1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson16_条件分支语句if练习", "Lesson16_if语句练习\Lesson16_条件分支语句if练习.csproj", "{78484B21-A82F-4976-833B-5FF3D1B9C500}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson17_条件分支语句Switch", "Lesson17_条件分支语句Switch\Lesson17_条件分支语句Switch.csproj", "{F665FA1A-4EB9-48D8-BB93-3BDF9877362D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson17_条件分支语句Switch练习", "Lesson17_条件分支语句Switch练习\Lesson17_条件分支语句Switch练习.csproj", "{4C056E34-110B-442B-8F90-6C2B212CFA09}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson18_循环语句while", "Lesson18_循环语句while\Lesson18_循环语句while.csproj", "{C69CBFA5-EACB-4E07-9E10-FDA4D5F80166}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson19_循环语句dowhile", "Lesson19_循环语句dowhile\Lesson19_循环语句dowhile.csproj", "{16573E5F-7BC5-4BEF-9DFB-7A1012C0BD8B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson20_循环语句for", "Lesson19_循环语句for\Lesson20_循环语句for.csproj", "{D41F92B9-051D-4FF8-8AC0-9454A44FA31D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B5D2D87D-A962-4B4D-8D55-913F4B5D2467}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5D2D87D-A962-4B4D-8D55-913F4B5D2467}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5D2D87D-A962-4B4D-8D55-913F4B5D2467}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5D2D87D-A962-4B4D-8D55-913F4B5D2467}.Release|Any CPU.Build.0 = Release|Any CPU
{38D8CC7A-769C-4DE9-9835-54916128D614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38D8CC7A-769C-4DE9-9835-54916128D614}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38D8CC7A-769C-4DE9-9835-54916128D614}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38D8CC7A-769C-4DE9-9835-54916128D614}.Release|Any CPU.Build.0 = Release|Any CPU
{2E255F6C-89D2-4ECE-AC3F-4903A5D23765}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E255F6C-89D2-4ECE-AC3F-4903A5D23765}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E255F6C-89D2-4ECE-AC3F-4903A5D23765}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E255F6C-89D2-4ECE-AC3F-4903A5D23765}.Release|Any CPU.Build.0 = Release|Any CPU
{6BDC7E93-4AE2-4FD5-BD04-65720EDF0897}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BDC7E93-4AE2-4FD5-BD04-65720EDF0897}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BDC7E93-4AE2-4FD5-BD04-65720EDF0897}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BDC7E93-4AE2-4FD5-BD04-65720EDF0897}.Release|Any CPU.Build.0 = Release|Any CPU
{12B6A100-ABDE-40E8-B6F0-6FA53A805D9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{12B6A100-ABDE-40E8-B6F0-6FA53A805D9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12B6A100-ABDE-40E8-B6F0-6FA53A805D9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12B6A100-ABDE-40E8-B6F0-6FA53A805D9F}.Release|Any CPU.Build.0 = Release|Any CPU
{29321A63-B872-4C19-B9B2-AEBD90D21697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29321A63-B872-4C19-B9B2-AEBD90D21697}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29321A63-B872-4C19-B9B2-AEBD90D21697}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29321A63-B872-4C19-B9B2-AEBD90D21697}.Release|Any CPU.Build.0 = Release|Any CPU
{536E2B30-EA7F-4D2F-AE45-B518B988253D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{536E2B30-EA7F-4D2F-AE45-B518B988253D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{536E2B30-EA7F-4D2F-AE45-B518B988253D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{536E2B30-EA7F-4D2F-AE45-B518B988253D}.Release|Any CPU.Build.0 = Release|Any CPU
{2925D024-47CC-4632-9CCE-DB7C2EE597CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2925D024-47CC-4632-9CCE-DB7C2EE597CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2925D024-47CC-4632-9CCE-DB7C2EE597CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2925D024-47CC-4632-9CCE-DB7C2EE597CA}.Release|Any CPU.Build.0 = Release|Any CPU
{D47510F0-704D-4BB6-B814-4E7C5FA7F6D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D47510F0-704D-4BB6-B814-4E7C5FA7F6D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D47510F0-704D-4BB6-B814-4E7C5FA7F6D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D47510F0-704D-4BB6-B814-4E7C5FA7F6D4}.Release|Any CPU.Build.0 = Release|Any CPU
{DE655809-4BE0-46CE-A6AF-576B2AD80AB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE655809-4BE0-46CE-A6AF-576B2AD80AB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE655809-4BE0-46CE-A6AF-576B2AD80AB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE655809-4BE0-46CE-A6AF-576B2AD80AB3}.Release|Any CPU.Build.0 = Release|Any CPU
{C3B313DE-D643-42EE-BF8B-0197CBE0096B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3B313DE-D643-42EE-BF8B-0197CBE0096B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3B313DE-D643-42EE-BF8B-0197CBE0096B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3B313DE-D643-42EE-BF8B-0197CBE0096B}.Release|Any CPU.Build.0 = Release|Any CPU
{96CB3658-80EE-4F20-9A1B-79D43C25DEDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96CB3658-80EE-4F20-9A1B-79D43C25DEDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96CB3658-80EE-4F20-9A1B-79D43C25DEDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96CB3658-80EE-4F20-9A1B-79D43C25DEDF}.Release|Any CPU.Build.0 = Release|Any CPU
{2B9B9029-A2B0-4EAF-8C3D-1840C23209C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B9B9029-A2B0-4EAF-8C3D-1840C23209C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B9B9029-A2B0-4EAF-8C3D-1840C23209C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B9B9029-A2B0-4EAF-8C3D-1840C23209C3}.Release|Any CPU.Build.0 = Release|Any CPU
{29A255F2-FFD0-4749-889A-C473BD8B1A01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29A255F2-FFD0-4749-889A-C473BD8B1A01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29A255F2-FFD0-4749-889A-C473BD8B1A01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29A255F2-FFD0-4749-889A-C473BD8B1A01}.Release|Any CPU.Build.0 = Release|Any CPU
{31DA648B-6D43-491D-8F74-A88095D778E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31DA648B-6D43-491D-8F74-A88095D778E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31DA648B-6D43-491D-8F74-A88095D778E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31DA648B-6D43-491D-8F74-A88095D778E1}.Release|Any CPU.Build.0 = Release|Any CPU
{90AE5DB8-797B-4D1D-B9C8-931B9CB031CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90AE5DB8-797B-4D1D-B9C8-931B9CB031CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90AE5DB8-797B-4D1D-B9C8-931B9CB031CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90AE5DB8-797B-4D1D-B9C8-931B9CB031CC}.Release|Any CPU.Build.0 = Release|Any CPU
{390F2AAE-DADB-4054-B168-C4060195924F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{390F2AAE-DADB-4054-B168-C4060195924F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{390F2AAE-DADB-4054-B168-C4060195924F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{390F2AAE-DADB-4054-B168-C4060195924F}.Release|Any CPU.Build.0 = Release|Any CPU
{C09FCC0C-79AC-4B56-8AE1-9914E2D9E2B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C09FCC0C-79AC-4B56-8AE1-9914E2D9E2B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C09FCC0C-79AC-4B56-8AE1-9914E2D9E2B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C09FCC0C-79AC-4B56-8AE1-9914E2D9E2B2}.Release|Any CPU.Build.0 = Release|Any CPU
{B9E82214-EFF4-4060-998D-6A2FBB1BD09C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9E82214-EFF4-4060-998D-6A2FBB1BD09C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9E82214-EFF4-4060-998D-6A2FBB1BD09C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9E82214-EFF4-4060-998D-6A2FBB1BD09C}.Release|Any CPU.Build.0 = Release|Any CPU
{8C3FDC09-CC22-460A-AB0C-E25BD103C7CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C3FDC09-CC22-460A-AB0C-E25BD103C7CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C3FDC09-CC22-460A-AB0C-E25BD103C7CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C3FDC09-CC22-460A-AB0C-E25BD103C7CF}.Release|Any CPU.Build.0 = Release|Any CPU
{8D709A42-B8AA-4427-91DE-C9959F93F1A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D709A42-B8AA-4427-91DE-C9959F93F1A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D709A42-B8AA-4427-91DE-C9959F93F1A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D709A42-B8AA-4427-91DE-C9959F93F1A6}.Release|Any CPU.Build.0 = Release|Any CPU
{0FC71AB1-4975-41ED-8DDA-6743C6622614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FC71AB1-4975-41ED-8DDA-6743C6622614}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FC71AB1-4975-41ED-8DDA-6743C6622614}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FC71AB1-4975-41ED-8DDA-6743C6622614}.Release|Any CPU.Build.0 = Release|Any CPU
{563D0FEB-699D-4B22-8187-07A53891FF78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{563D0FEB-699D-4B22-8187-07A53891FF78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{563D0FEB-699D-4B22-8187-07A53891FF78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{563D0FEB-699D-4B22-8187-07A53891FF78}.Release|Any CPU.Build.0 = Release|Any CPU
{B33DAB08-87FA-4EC1-A78E-0E38D9021CA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B33DAB08-87FA-4EC1-A78E-0E38D9021CA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B33DAB08-87FA-4EC1-A78E-0E38D9021CA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B33DAB08-87FA-4EC1-A78E-0E38D9021CA5}.Release|Any CPU.Build.0 = Release|Any CPU
{5A54CA20-4B7A-48D5-B975-16BD8A7529BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A54CA20-4B7A-48D5-B975-16BD8A7529BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A54CA20-4B7A-48D5-B975-16BD8A7529BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A54CA20-4B7A-48D5-B975-16BD8A7529BC}.Release|Any CPU.Build.0 = Release|Any CPU
{E62F1255-E9C2-4738-B365-25BF5F6C6A1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E62F1255-E9C2-4738-B365-25BF5F6C6A1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E62F1255-E9C2-4738-B365-25BF5F6C6A1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E62F1255-E9C2-4738-B365-25BF5F6C6A1D}.Release|Any CPU.Build.0 = Release|Any CPU
{78484B21-A82F-4976-833B-5FF3D1B9C500}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78484B21-A82F-4976-833B-5FF3D1B9C500}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78484B21-A82F-4976-833B-5FF3D1B9C500}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78484B21-A82F-4976-833B-5FF3D1B9C500}.Release|Any CPU.Build.0 = Release|Any CPU
{F665FA1A-4EB9-48D8-BB93-3BDF9877362D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F665FA1A-4EB9-48D8-BB93-3BDF9877362D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F665FA1A-4EB9-48D8-BB93-3BDF9877362D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F665FA1A-4EB9-48D8-BB93-3BDF9877362D}.Release|Any CPU.Build.0 = Release|Any CPU
{4C056E34-110B-442B-8F90-6C2B212CFA09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C056E34-110B-442B-8F90-6C2B212CFA09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C056E34-110B-442B-8F90-6C2B212CFA09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C056E34-110B-442B-8F90-6C2B212CFA09}.Release|Any CPU.Build.0 = Release|Any CPU
{C69CBFA5-EACB-4E07-9E10-FDA4D5F80166}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C69CBFA5-EACB-4E07-9E10-FDA4D5F80166}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C69CBFA5-EACB-4E07-9E10-FDA4D5F80166}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C69CBFA5-EACB-4E07-9E10-FDA4D5F80166}.Release|Any CPU.Build.0 = Release|Any CPU
{16573E5F-7BC5-4BEF-9DFB-7A1012C0BD8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16573E5F-7BC5-4BEF-9DFB-7A1012C0BD8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16573E5F-7BC5-4BEF-9DFB-7A1012C0BD8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16573E5F-7BC5-4BEF-9DFB-7A1012C0BD8B}.Release|Any CPU.Build.0 = Release|Any CPU
{D41F92B9-051D-4FF8-8AC0-9454A44FA31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D41F92B9-051D-4FF8-8AC0-9454A44FA31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D41F92B9-051D-4FF8-8AC0-9454A44FA31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D41F92B9-051D-4FF8-8AC0-9454A44FA31D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DA94A9F6-4704-4633-BFDB-26B03F3689FA}
EndGlobalSection
EndGlobal
-43
View File
@@ -1,43 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36202.13 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test1", "test1\test1.csproj", "{431A94A0-24B2-497E-A1FE-693FA2EF350F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson1注释&输入输出", "lesson1\Lesson1注释&输入输出.csproj", "{C9D85F7A-86E5-4034-AA0B-F469E441F9C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson1练习题", "Lession1练习题\Lesson1练习题.csproj", "{D965940D-E758-4A7C-977A-74E5793C593B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson2变量", "Lesson2变量\Lesson2变量.csproj", "{21CE6A7D-CC82-4F41-A28F-54D2E535FB3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{431A94A0-24B2-497E-A1FE-693FA2EF350F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{431A94A0-24B2-497E-A1FE-693FA2EF350F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{431A94A0-24B2-497E-A1FE-693FA2EF350F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{431A94A0-24B2-497E-A1FE-693FA2EF350F}.Release|Any CPU.Build.0 = Release|Any CPU
{C9D85F7A-86E5-4034-AA0B-F469E441F9C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9D85F7A-86E5-4034-AA0B-F469E441F9C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9D85F7A-86E5-4034-AA0B-F469E441F9C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9D85F7A-86E5-4034-AA0B-F469E441F9C5}.Release|Any CPU.Build.0 = Release|Any CPU
{D965940D-E758-4A7C-977A-74E5793C593B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D965940D-E758-4A7C-977A-74E5793C593B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D965940D-E758-4A7C-977A-74E5793C593B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D965940D-E758-4A7C-977A-74E5793C593B}.Release|Any CPU.Build.0 = Release|Any CPU
{21CE6A7D-CC82-4F41-A28F-54D2E535FB3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21CE6A7D-CC82-4F41-A28F-54D2E535FB3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21CE6A7D-CC82-4F41-A28F-54D2E535FB3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21CE6A7D-CC82-4F41-A28F-54D2E535FB3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {972D1D6C-AC89-49B8-9AE0-EB671A0842D5}
EndGlobalSection
EndGlobal
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,140 @@
using System;
namespace Lesson10
{
class program
{
static void Main(string[] args)
{
Console.WriteLine("算术运算符");
//算数运算符 是用于 数值类型变量计算的运算符
//他返回的结果是数值
#region
// = 赋值运算符
// 关键知识点:
// 先看右侧 再看左侧 把右侧的值赋给左侧的变量
string myName = "HK";// 先看右侧 "HK" 再看左侧 myName 把 "HK" 赋值给 myName
int myAge = 18; // 先看右侧 18 再看左侧 myAge 把 18 赋值给 myAge
float myHeight = 1.75f; // 先看右侧 1.75f 再看左侧 myHeight 把 1.75f 赋值给 myHeight
#endregion
#region
#region +
// 用自己计算 先算右侧结果 再赋值给左侧变量
int i = 1;
i = i + 2;//先算右侧 i + 2 = 3 再赋值给左侧 i
Console.WriteLine("i = " + i); // 输出 i = 3
//连续运算 先算右侧结果 再赋值给左侧变量
i = i + 2 + 3; //先算右侧 i + 2 + 3 = 8 再赋值给左侧 i
Console.WriteLine("i = " + i); // 输出 i = 8
//初始化时就运算 先算右侧结果 再赋值给左侧变量
int j = 1 + 2 + 3; //先算右侧 1 + 2 + 3 = 6 再赋值给左侧 j
Console.WriteLine("j = " + j); // 输出 j = 6
#endregion
#region -
// 同加法
#endregion
#region *
// 乘法运算符 * 用于两个数相乘
int k = 2 * 3; //先算右侧 2 * 3 = 6 再赋值给左侧 k
Console.WriteLine("k = " + k); // 输出 k = 6
// 乘法也可以连续运算
k = k * 2 * 3; //先算右侧 k * 2 * 3 = 36 再赋值给左侧 k
Console.WriteLine("k = " + k); // 输出 k = 36
#endregion
#region /
// 除法运算符 / 用于两个数相除
int m = 6 / 2; //先算右侧 6 / 2 = 3 再赋值给左侧 m
Console.WriteLine("m = " + m); // 输出 m = 3
// 除法也可以连续运算
m = m / 2 / 3; //先算右侧 m / 2 / 3 = 0 再赋值给左侧 m
Console.WriteLine("m = " + m); // 输出 m = 0
// 注意:除法运算如果除数为0,会抛出异常
try
{
int n = 6 / 0; //会抛出异常
}
catch (DivideByZeroException ex)
{
Console.WriteLine("除数不能为0" + ex.Message);
}
#endregion
#region %
// 取余运算符 % 用于两个数相除后,返回余数
int o = 7 % 3; //先算右侧 7 % 3 = 1 再赋值给左侧 o
Console.WriteLine("o = " + o); // 输出 o = 1
o = o / 3;
Console.WriteLine("o = " + o); // 输出 o = 0
// 注意:取余运算如果除数为0,会抛出异常
o = o / 3;
try
{
int p = 7 % 0; //会抛出异常
}
catch (DivideByZeroException ex)
{
Console.WriteLine("除数不能为0" + ex.Message);
}
#endregion
#endregion
#region
// 乘除取余运算符优先级高于加减运算符
// 先算乘除取余运算符 再算加减运算符
int a = 1 + 2 * 3 / 2 + 1;//先算右侧 2 * 3 = 6 再算 6 / 2 = 3 再算 1 + 3 + 1 = 5
Console.WriteLine(a);
//括号可以改变运算顺序
int b = (1 + 2) * 3 / 2 + 1; //先算右侧 (1 + 2) = 3 再算 3 * 3 = 9 再算 9 / 2 = 4.5 再算 4.5 + 1 = 5.5
Console.WriteLine(b);
//注意:括号内的运算优先级最高
//多组括号 可以嵌套运算 先算最内层括号
int c = (1 + (2 * 3)) / 2 + 1; //先算右侧 (2 * 3) = 6 再算 (1 + 6) = 7 再算 7 / 2 = 3.5 再算 3.5 + 1 = 4.5
Console.WriteLine(c);
#endregion
#region
// 复合运算符号 是对算数运算符的简化写法
// += 复合加法运算符
i += 2; //等价于 i = i + 2; 先算右侧 i + 2 = 10 再赋值给左侧 i
// -= 复合减法运算符
i -= 2; //等价于 i = i - 2; 先算右侧 i - 2 = 8 再赋值给左侧 i
// *= 复合乘法运算符
i *= 2; //等价于 i = i * 2; 先算右侧 i * 2 = 16 再赋值给左侧 i
// /= 复合除法运算符
i /= 2; //等价于 i = i / 2; 先算右侧 i / 2 = 8 再赋值给左侧 i
// %= 复合取余运算符
i %= 2;//等价于 i = i % 2; 先算右侧 i % 2 = 0 再赋值给左侧 i
#endregion
#region
// 自增自减运算符 是对变量的值进行加1或减1的运算符
i = i + 1;
i += 1;
i++;
++i;
//以上四种写法是等价的
//但是也有区别
i++;//表示的意思是先使用 i 的值,然后再加1
++i;//表示的意思是先加1,然后再使用 i 的值
//自减运算符同理
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,55 @@
using System;
namespace Lesson10
{
class program
{
static void Main(string[] args)
{
#region
int myAge = 18;
myAge += 10;
Console.WriteLine("十年后我的年龄是:" + myAge);
#endregion
#region
const float PI = 3.1415926f;
int radius = 5;
float area = PI * radius * radius;
float circumference = 2f * PI * radius;
Console.WriteLine("半径为" + radius + "的圆的面积是:" + area + "周长是:" + circumference);
#endregion
#region
int score1 = 80;
int score2 = 90;
int score3 = 92;
int totalScore = score1 + score2 + score3;
float avgScore = totalScore / 3.0f;
Console.WriteLine("你的总成绩为:" + totalScore);
Console.WriteLine("你的平均分为:" + avgScore);
#endregion
#region
int a = 99;
int b = 87;
int temp;
temp = a;
a = b;
b = temp;
Console.WriteLine($"交换后A的值为:{a}B的值为:{b}");
#endregion
#region
int second = 987652;
int hour, minute, day;
day = second / 86400; // 1天 = 86400秒
hour = (second - (day * 86400)) / 3600; // 1小时 = 3600秒
minute = (second - (day * 86400 + hour * 3600)) / 60; // 1分钟 = 60秒
second = second - (day * 86400 + hour * 3600 + minute * 60);
Console.WriteLine($"转换后的时间为{day}天{hour}小时{minute}分钟{second}秒");
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,68 @@
using System;
namespace lesson11
{
class program
{
static void Main(string[] args)
{
Console.WriteLine("字符串拼接");
Console.WriteLine();
#region 1
//算数运算符只是用来数值运算
//而string不能来做数值运算
//但是可以用来做字符串拼接
Console.WriteLine("拼接方式一加号拼接:");
//字符串拼接的方式1:使用加号运算符
string str = "123";
str = str + "456"; //字符串拼接
Console.WriteLine(str);
str = str + 1;//1虽然没有加双引号,但它会被自动转换为字符串
Console.WriteLine(str);
//如果需要加上数值,可以先转换为数值类型,运算完成后再转换为字符串
str = (int.Parse(str) + Convert.ToInt32("1")).ToString();
Console.WriteLine(str);
//复合运算符也可以用来拼接字符串
str = "123";
str += "456" + 7 + true;
Console.WriteLine(str);
//但是要注意加号运算符拼接时,后面全是数值类型
str = "123";
str += 4 + 5;//这里因为运算规则,会先看右边全是数值类型,所以是以数值类型先运算完后再转换为字符串拼接
Console.WriteLine(str);
str = "123";
str += 1 + 2 + "" + 3 + 4;//这里会先运算1+2的结果再把3和4当作字符串拼接上去
Console.WriteLine(str);
//如果后方只拼接数值类型,但又不想被当作数值类型运算,可以直接套双引号或加空双引号""来避免这种问题
str = "123";
str += "" + 4 + 5;
Console.WriteLine(str);
Console.WriteLine();
#endregion
#region 2
//固定语法
//string.Format("待拼接的字符串", 内容1, 内容2, ...);
//拼接内容中的固定规则
//想要被拼接的内容用占位符{}来表示
//eg: "拼接内容{0},内容{1},内容{2}"
string str2 = string.Format("我是{0},今年{1}岁,我想要{2}", "ZJ", 18, "天天开心");
Console.WriteLine(str2);
Console.WriteLine();
#endregion
#region
//和方法二类似
Console.WriteLine("A{0},B{1},C{2}",1,2,3);
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,35 @@
using System;
namespace Lessson11_exercise
{
class program
{
static void Main(string[] args)
{
string customerName = "张三";
Console.WriteLine("你好,{0}",customerName);
Console.WriteLine();
string customerName2 = "李四";
int customerAge = 25;
Console.WriteLine("{0}今年{1}岁了\n", customerName2,customerAge);
string name = "小明";
int age = 20;
string email = "123@gmail.com";
string address = "北京市朝阳区某街道某小区";
string phone = "12345678901";
Console.WriteLine("姓名:{0}\n年龄:{1}\n邮箱:{2}\n地址:{3}\n电话:{4}\n", name, age, email, address, phone);
string username;
int age1;
string classes;
Console.WriteLine("请输入你的用户名:");
username = Console.ReadLine();
Console.WriteLine("请输入你的年龄:");
age1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入你的班级:");
classes = Console.ReadLine();
Console.WriteLine("你是{0}\n你今年{1}岁了\n班级是{2}\n",username,age1,classes);
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+23
View File
@@ -0,0 +1,23 @@
using System;
namespace lesson11
{
class program
{
static void Main(string[] args)
{
#region 1
string customerName = "张三";
Console.WriteLine("你好"+customerName);
Console.WriteLine("你好{0}", customerName);
string str = string.Format("你好{0}", customerName);
Console.WriteLine(str);
#endregion
#region 2
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,88 @@
using System;
namespace lesson12_条件运算符
{
class program
{
static void Main(String[] args)
{
#region
//用于比较两个变量或常量
// 是否大于 >
// 是否小于 <
// 是否大于等于 >=
// 是否小于等于 <=
// 是否等于 ==
// 是否不等于 !=
// 条件运算符一定存在两边的内容
// 左边的内容 条件运算符 右边的内容
int a = 5;
int b = 10;
// a > b; 判断 a 是否大于 b
// 结果是一个布尔值 true 或 false
bool result = a > b; // 将结果赋值给变量
Console.WriteLine(result); // 输出结果
Console.WriteLine(a < b);
#endregion
#region
a = 5;
b = 10;
//变量和变量的比较
result = a > b; // false
//变量和常量的比较
result = a < 10;//true
result = b > 5;//true
//数值和数值的比较
result = 5 < 10; // true
result = 10 >= 5; // true
result = 5 != 10; // true
//计算结果比较(优先级知识点)
result = a+3 > b-2; // true
#endregion
#region
a = 5;
//判断是否在某个范围内
// 1 < a < 10; // 错误的写法,不能直接使用范围比较
// 需要使用逻辑运算符来实现范围比较
// 正确的写法是使用逻辑与运算符 && 来连接两个条件
result = a > 1 && a < 10; // true
#endregion
#region
// 不同类型的比较会发生隐式转换
int i = 5;
float f = 1.2f;
double d = 12.4;
short s = 2;
byte by = 20;
uint ui = 222;
result = i > f; // true, int 和 float 比较,int 转换为 float
result = f < d; // true, float 和 double 比较,float 转换为 double
result = i < by; // true, int 和 byte 比较,byte 转换为 int
result = i < ui; // true, int 和 uint 比较,int 转换为 uint
//特殊类型 char string bool 只能和同类型进行 == 和 != 比较
string str = "123";
char fc = 'A';
bool bo = true;
result = str == "123"; // true, string 和 string 比较
result = str == "234"; // false, string 和 string 比较
//char不仅可以和 char 比较,还可以和 int 比较
char c = 'A';
result = c > 123; // true, char 和 int 比较,char 转换为 int
result = c > 'a'; // true, char 和 char 比较
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,35 @@
using System;
namespace Lesson12_练习题
{
class Program
{
static void Main(string[] args)
{
#region
//请回答一下问题:
//我的年龄(18>你们的年龄(22)false
//兔子的速度(3m/s<乌龟的速度(1m/sfalse
//狗的重量(50kg<兔子的重量(2kgfalse
//我有钱(10元)==你有钱(10元)true
#endregion
#region
//bool b = true;
//console.WriteLine(b != true); false
//console.WriteLine(10==10); ture
//console.WriteLine(10 > 20); false
//console.WriteLine(10 <= 20); true
//console.WriteLine(10 <= 10); true
#endregion
#region
//bool gameOver,startGame;
//int a = 10,b = 15;
//gameOver = a > (b - 5);
//startGame = gameOver == (b > (a + 5));
//console.WriteLine("stratGame = " + startGame);
//true
#endregion
}
}
}
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Lesson13__逻辑运算符</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,82 @@
using System;
namespace Lesson12_逻辑运算符
{
class program
{
static void Main(string[] args)
{
#region
//符号&&
//规则:对两个bool值进行逻辑与运算,只有当两个值都为true时,结果才为true,否则为false。
bool result = true && false;
Console.WriteLine(result); // 输出: False
result = true && true;
Console.WriteLine(result); // 输出: True
//bool相关类型 bool变量 条件运算符
//逻辑运算符优先级 低于 条件运算符 和 关系运算符
result = 3 > 1 && 1 < 2;// 先计算关系运算符,再计算逻辑运算符
Console.WriteLine(result);// 输出: True
int i = 3;
result = i > 1 && i < 5; // 先计算关系运算符,再计算逻辑运算符
Console.WriteLine(result); // 输出: True
#endregion
#region
//符号||
//规则:对两个bool值进行逻辑或运算,只要有一个值为true,结果就为true,否则为false。
result = true || false;
Console.WriteLine(result);// 输出: True
result = false || true;
Console.WriteLine(result);// 输出: True
result = true || true;
Console.WriteLine(result);// 输出: True
result = false || false;
Console.WriteLine(result);// 输出: False
#endregion
#region
//符号!
//规则:对一个bool值进行取反,真变假,假变真
result = !true;
Console.WriteLine(result);// 输出:false
result = !false;
Console.WriteLine(result);// 输出:true
result = !!false;
Console.WriteLine(result);// 输出:false
//result = !3 > 2;
//逻辑非的优先级较高会直接报错必须要套括号
result = !(3 > 2);
Console.WriteLine(result);// 输出:false
#endregion
#region 使
//规则 !(逻辑非)的优先级最高,&&(逻辑与)的优先级高于||(逻辑或)
//逻辑运算符优先级 低于 算术运算符 条件运算符
bool gameOver = false;
int hp = 100;
bool isDead = false;
bool isMustOver = true;
result = gameOver || hp < 0 && !isDead || isMustOver;
Console.WriteLine(result);//输出 True
#endregion
#region
int i3 = 1;
//短路
result = i3 > 0 || ++i3 >= 1;//i3此时不会+1为2
Console.WriteLine(i3);
Console.WriteLine(result);//输出true
//在左边i3 > 0运算后,已经出现了boolean值,后面的表达式不会计算了
//概念:只要逻辑与 或者 逻辑或 左边已经满足了条件,后面的结果不会继续运算了
result = ++i3 >= 1 && i3 < 0;//i3此时会先进行运算
Console.WriteLine(i3);
Console.WriteLine(result);//输出false
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,27 @@
using System;
namespace Lesson13
{
class program
{
static void Main(string[] args)
{
#region
//求打印结果
//Console.WriteLine(true || true); true
//Console.WriteLine(false || true); true
//Console.WriteLine(true && true); true
//Console.WriteLine(true && false); false
//Console.WriteLine(!true);false
#endregion
#region
//求打印结果
bool gameOver;
bool isWin;
int health = 100;
gameOver = true;
isWin = false;
Console.WriteLine(gameOver || isWin && health > 0);//true
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+64
View File
@@ -0,0 +1,64 @@
using System;
namespace Lesson14
{
class program
{
static void Main(string[] args)
{
//位运算主要使用数值类型计算
//将数值类型转换为二进制形式进行计算
//位运算符包括:& | ^ ~ << >>
#region &
// 规则 连接两个数值进行位与运算 将数值转为二进制
// 对位运算 有0则0
int a = 1;//001
int b = 5;//101
int c = a & b;
// 001 & 101 = 001
Console.WriteLine(c);//001 & 101 = 001
Console.WriteLine(10 & 5);//1010 & 0101 = 0000
Console.WriteLine(3 & 19);//00011 & 10011 = 00011
Console.WriteLine(19 & 3);//10011 & 00011 = 00011
Console.WriteLine(1 & 2);//01 & 10 = 00
//有点像是取最小的数,但不实际是这样
#endregion
#region |
// 规则 连接两个数值进行位或运算 将数值转为二进制
// 对位运算 有1则1
Console.WriteLine(2 & 3);// 00010 & 00011 = 00011
Console.WriteLine(3 & 2);// 00011 & 00010 = 00011
Console.WriteLine(12 & 3);// 00001100 & 00000011 = 00000000
#endregion
#region ^
// 规则 连接两个数值进行位异或运算 将数值转为二进制
// 对位运算 相同为0 不同为1
Console.WriteLine(2 ^ 3);// 00010 ^ 00011 = 00001
Console.WriteLine(3 ^ 2);// 00011 ^ 00010 = 00001
Console.WriteLine(12 ^ 3);// 00001100 ^ 00000011 = 00001111
#endregion
#region ~
// 规则 连接一个数值进行位非运算 将数值转为二进制
// 对位运算 0变1 1变0
Console.WriteLine(~2);// ~00010 = 11101 = -3
// 但是要注意,特定变量类型前面的位会补全例如int
int test = 10;
Console.WriteLine(~test);// ~00000000000000000000000000001010 = 11111111111111111111111111110101 = -11
#endregion
#region << >>
// 规则 左移运算符将数值的二进制位向左移动指定的位数,右移运算符将数值的二进制位向右移动指定的位数
// 左移相当于乘以2的n次方 右移相当于除以2的n次方
a = 5;// 101
c = a << 5; // 5左移5位
Console.WriteLine(c);// 10100000 = 160
//右移同理
c = a >> 2; // 5右移2位
Console.WriteLine(c);// 00000101 >> 2 = 00000001 = 1
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,31 @@
using System;
namespace lesson14
{
class program
{
static void Main(string[] args)
{
#region
// 35 << 4 和 66 >> 1 的结果是多少?
// 35 = 00100011
// 35 << 4 = 001000110000 = 560
Console.WriteLine(35 << 4);
// 66 = 01000010
// 66 >> 1 = 00100001 = 33
Console.WriteLine(66 >> 1);
#endregion
#region
// 99 ^ 33 和 76 | 85 的结果是多少?
// 99 = 01100011
// 33 = 00100001
// 99 ^ 33 = 01000010 = 66
Console.WriteLine(99 ^ 33);
// 76 = 01001100
// 85 = 01010101
// 76 | 85 = 01011101 = 125
Console.WriteLine(76 | 85);
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,29 @@
using System;
namespace lesson15
{
class program
{
static void Main(string[] args)
{
#region
// 套路: 3个空位 2个符号
// 固定语法:空位 ?空位 :空位
// 关键信息:bool类型 ?bool类型为真返回内容 :bool类型为假返回内容
// 三目运算符会有返回值,这个返回值类型必须一致且必须被使用
#endregion
#region
string str = true ? "条件为真" : "条件为假";
Console.WriteLine(str);// 输出:条件为真
str = false ? "条件为真" : "条件为假";
Console.WriteLine(str);// 输出:条件为假
int a = 5;
str = a > 1 ? "a大于1" : "a小于等于1";
bool b = a > 1 ? a > 6 : !false;
Console.WriteLine(b);// 输出:False
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,18 @@
#region
//比较两个数的大小,求出最大的
//int a = 10;
//int b = 15;
//string str = a > b ? "a大于b" : "b大于等于a";
//Console.WriteLine(str); // 输出:b大于等于a
Console.WriteLine("请输入两个数来比较大小");
Console.WriteLine("请输入第一个数:");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("请输入第二个数:");
int b = int.Parse(Console.ReadLine());
string result = a > b ? "第一个数大于第二个数" : "第二个数大于等于第一个数";
Console.WriteLine(result);
#endregion
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+99
View File
@@ -0,0 +1,99 @@
using System;
namespace Lesson16
{
class program
{
static void Main(string[] args)
{
#region
//让顺序执行的代码 产生分支
//
#endregion
#region if语句
//作用:满足条件时 多执行一些代码
//语法:
//if (条件表达式) { 代码块 }
//if (条件表达式) { 代码块 } else { 代码块 }
//if (条件表达式) { 代码块 } else if (条件表达式) { 代码块 } else { 代码块 }
//条件表达式:返回true或false的bool值表达式
//只有返回值为true时,代码块才会执行
//else:可选,表示条件不满足时执行的代码块
//注意:
//1.if语句条件表达式部分不用写分号
//2.if语句可以嵌套使用
//
Console.WriteLine("这是代码块外的代码");
if (true)
{
Console.WriteLine("进入了if语句代码块,执行了其中的代码逻辑");
}//会被执行打印
Console.WriteLine("这是代码块外的代码");
if (false)
{
Console.WriteLine("进入了if语句代码块,执行了其中的代码逻辑");
}//不会被执行
//例子
int a = 1;
if (a == 1)
{
Console.WriteLine("满足a == 1条件");
}
a = 1;
if (a >= 0 && a <= 5)
{
Console.WriteLine("满足0<a<5条件");
}
//例子2
string name = "HK";
string passWord = "666";
if ( name == "HK" && passWord == "666" )
{
Console.WriteLine("登录成功");
}
//嵌套使用例子
if ( name == "HK")
{
Console.WriteLine("用户名可用");
if ( passWord == "666")
{
Console.WriteLine("密码验证成功");
}
}
//if else例子
//注意:
//1.if else语句中else部分的条件表达式是可选的
//2.else部分的代码块会在if条件不满足时执行
//3.在第一个else if被执行后,后续的else if和else部分将不会被执行,这样可以避免多次执行代码块
if (name == "HK")
{
Console.WriteLine("用户名可用");
}
else
{
Console.WriteLine("用户名不可用");
}
//if else if 例子
if (name == "HK")
{
Console.WriteLine("用户名可用");
}
else if (name == "HK2")
{
Console.WriteLine("用户名可用2");
}
else
{
Console.WriteLine("用户名不可用");
}
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+146
View File
@@ -0,0 +1,146 @@

#region
//try
//{
// Console.Write("请输入你今天看教学的时长:");
// int time = Convert.ToInt16(console.readline());
// if (time >= 60)
// {
// Console.WriteLine("今天看视频花了{0}分钟,看来你离成功又近了一步!", time);
// }
// else Console.WriteLine("请继续努力");
//}
//catch
//{
// Console.WriteLine("输入格式有误请重新重试");
//}
#endregion
#region
//try
//{
// int yuWen, shuXue, yingYu;
// Console.Write("请输入你的语文成绩:");
// yuWen = Convert.ToInt16(Console.ReadLine());
// Console.Write("请输入你的数学成绩:");
// shuXue = Convert.ToInt16(Console.ReadLine());
// Console.Write("请输入你的英语成绩:");
// yingYu = Convert.ToInt16(Console.ReadLine());
// if (yuWen >= 70 && shuXue >= 80 && yingYu >= 90)
// {
// Console.WriteLine("非常棒,请继续加油");
// }
// else if (yuWen >= 90 && (shuXue >= 70 || yingYu >= 70))
// {
// Console.WriteLine("非常棒,请继续加油");
// }
// else if (yuWen == 100 && shuXue == 100 && yingYu == 100)
// {
// Console.WriteLine("非常棒,请继续加油");
// }
// else Console.WriteLine("请你继续加油");
//}
//catch
//{
// Console.WriteLine("输入的格式有误");
//}
#endregion
#region
//Console.Write("请输入你的成绩:");
//try
//{
// int score = int.Parse(Console.ReadLine());
// if (score >= 90)
// {
// Console.WriteLine("奖励一百");
// }
// else Console.WriteLine("一个月不准玩游戏");
//}
//catch
//{
// Console.WriteLine("输入有误");
//}
#endregion
#region
//int a, b;
//try
//{
// Console.WriteLine("请输入A的值:");
// a = Convert.ToInt32(Console.ReadLine());
// Console.WriteLine("请输入B的值:");
// b = Convert.ToInt32(Console.ReadLine());
// if (a+b >= 100)
// {
// Console.WriteLine(a);
// }
// else if (a%b==0 || b%a == 0)
// {
// Console.WriteLine(a);
// }
// else Console.WriteLine(b);
//}
//catch
//{
// Console.WriteLine("输入格式有误");
//}
#endregion
#region
//try
//{
// Console.WriteLine("请输入一个数");
// int num = int.Parse(Console.ReadLine());
// if (num % 2==0)
// {
// Console.WriteLine("这是个偶数");
// }
// else Console.WriteLine("这是个奇数");
//}
//catch
//{
// Console.WriteLine("你输入的格式有误");
//}
#endregion
#region
//int num1 = 1, num2 = 2, num3 = 0;
//if (num1 >= num2 && num1 >= num3)
//{
// Console.WriteLine("num1:{0}",num1);
//}
//else if (num2 >= num1 && num2 >= num3)
//{
// Console.WriteLine("num2:{0}",num2);
//}
//else Console.WriteLine("num3:{0}", num3);
#endregion
#region
//Console.Write("请输入一个字符");
//int num = Console.ReadKey().KeyChar;
//Console.WriteLine();
//if ('0' <= num && '9' >= num)
//{
// Console.WriteLine("你输入的是一个数字");
//}
//else
//{
// Console.WriteLine("这不是一个数字");
//}
#endregion
#region
Console.WriteLine("太简单不做了");
#endregion
#region
#endregion
#region
#endregion
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,114 @@
using System;
namespace Lesson17_条件分支语句Switch
{
class Program
{
static void Main(string[] args)
{
#region
//让顺序的代码产生分支
#endregion
#region
//switch(变量)
//{
// case 常量1:
// //执行语句1
// break;
// case 常量2:
// //执行语句2
// break;
// default:
// //case条件都不满足执行默认语句
// break;
//}
//注意:常量只能是一个值,不能是条件/逻辑运算符
int a = 3;
switch (a)
{
case 1:
Console.WriteLine("a的值是1");
break;
case 2:
Console.WriteLine("a的值是2");
break;
case 3:
Console.WriteLine("a的值是3");
break;
default:
Console.WriteLine("没有满足的条件");
break;
}
//switch一般配合枚举使用
#endregion
#region default可省略
string str = "123";
switch (str)
{
case "321":
Console.WriteLine("值为1");
break;
case "213":
Console.WriteLine("值为123");
break;
//不写default,什么都不会运行
}
#endregion
#region
char c = 'A';
const char c2 = 'A';//常量必须const初始化,且不能修改
switch (c)
{
case c2:
Console.WriteLine("值为A");
break;
case 'B':
Console.WriteLine("值为B");
break;
default:
Console.WriteLine("没有满足的条件");
break;
}
#endregion
#region 穿
int aa = 1;
switch (aa)
{
case 1:
Console.WriteLine("aa的值是1");
goto case 2; //贯穿到case 2
case 2:
Console.WriteLine("aa的值是2");
break;
case 3:
Console.WriteLine("aa的值是3");
break;
default:
Console.WriteLine("没有满足的条件");
break;
}
//贯穿是指在一个case中没有使用break语句,直接跳转到下一个case
//注意:贯穿会导致后续的case也被执行,除非遇到break或default
switch (aa)
{
case 1://会直接进入case 2
case 2:
case 3:
case 4:
Console.WriteLine("这是一个数字");
break;
default:
Console.WriteLine("这是一个其他类型");
break;
}
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,135 @@
using System;
namespace Lesson17_条件分支语句Switch练习
{
class Program
{
static void Main(string[] args)
{
#region
int salary = 4000;
string comment;
Console.WriteLine("请输入你的评价:");
try
{
comment = Console.ReadLine();
switch (comment)
{
case "很兴奋":
salary += 500;
break;
case "很充实":
break;
case "还好吧":
salary -= 300;
break;
case "难理解":
salary -= 500;
break;
case "很无聊":
salary -= 800;
break;
default:
Console.WriteLine("请你输入正确的评价");
break;
}
Console.WriteLine("唐老师的工资是{0}", salary);
}catch (Exception ex)
{
Console.WriteLine("发生异常:{0}", ex.Message);
}
#endregion
#region
int money = 10;
int choice;
Console.WriteLine("菜单:\n1=中杯,¥5\n2=大杯,¥7\n3=超大杯,¥11\n请你选择需要购买的咖啡:");
try
{
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
money -= 5;
if (money < 0)
{
Console.WriteLine("余额不足");
break;
}
Console.WriteLine("你买了中杯,还剩{0}元",money);
break;
case 2:
money -= 7;
if (money < 0)
{
Console.WriteLine("余额不足");
break;
}
Console.WriteLine("你买了大杯,还剩{0}元", money);
break;
case 3:
money -= 11;
if (money < 0)
{
Console.WriteLine("余额不足");
break;
}
Console.WriteLine("你买了超大杯,还剩{0}元", money);
break;
default:
Console.WriteLine("没有这个选项,请重新选择。");
break;
}
}catch (FormatException)
{
Console.WriteLine("输入格式错误,请输入数字。");
return;
}
catch (Exception ex)
{
Console.WriteLine("发生异常:{0}", ex.Message);
return;
}
#endregion
#region
Console.WriteLine("请你输入你的考试成绩:");
try {
int score = int.Parse(Console.ReadLine());
switch (score)
{
case < 0:
Console.WriteLine("成绩不能为负数,请重新输入。");
break;
case <= 60:
Console.WriteLine("不及格");
break;
case <= 80:
Console.WriteLine("良好");
break;
case <= 90:
Console.WriteLine("优秀");
break;
case <= 100:
Console.WriteLine("满分");
break;
default:
Console.WriteLine("成绩超过100分,请重新输入。");
break;
}
}catch (FormatException)
{
Console.WriteLine("输入格式错误,请输入数字。");
return;
}
catch (Exception ex)
{
Console.WriteLine("发生异常:{0}", ex.Message);
return;
}
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,64 @@
using System;
namespace Lesson18_循环语句while
{
class Program
{
static void Main(string[] args)
{
#region
// 让程序重复执行某段代码,直到满足特定条件为止。
#endregion
#region
// while (bool类型的值)
// {
// // 需要循环执行的代码
// }
//进入unity之后 基本不会使用while循环
while (true)
{
Console.WriteLine("#");
// 这里的代码如果不被结束会一直执行
// 这种无限循环会导致程序无法结束,除非手动停止。
break; // 这里的 break 语句可以用来跳出循环
}
#endregion
#region 使
int a = 0;
int b = 0;
while (a < 5)
{
Console.WriteLine("#");
a++;
while (b < 5)
{
Console.WriteLine("*");
b++;
}
}
#endregion
#region
int count = 0;
while (count < 5)
{
Console.WriteLine("*");
count++;
if (count == 3)
{
Console.WriteLine("跳过当前循环");
continue; // 跳过当前循环的剩余部分,直接进入下一次循环
}
if (count == 4)
{
Console.WriteLine("结束循环");
break; // 结束整个循环
}
Console.WriteLine("当前计数: " + count);
}
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,41 @@
using System;
namespace Lesson19_循环语句dowhile
{
class Program
{
static void Main(string[] args)
{
#region
//和while循环类似,do while循环也是一种循环语句。
//区别在于do while循环会先执行一次循环体,然后再判断条件是否满足。
//do while循环的语法如下:
//do
//{
// // 循环体
//} while (条件);
//do while循环会先执行一次循环体,然后再判断条件是否满足。
#endregion
#region 使
int a = 1;
do
{
Console.WriteLine("a的值是{0}",a);
a++;
break;//防止死循环
} while (a>=2);
#endregion
#region
//if switch while dowhile都可以嵌套使用
do
{
Console.WriteLine("111");
continue;//这个循环只会打印一边111continue是回到while判断的地方而不是回到do
Console.WriteLine("222");//这串代码永远不会被运行
} while (false);
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,53 @@
using System;
namespace Lesson19_循环语句for
{
class Program
{
static void Main(string[] args)
{
#region
//格式
//for (初始表达式; 条件表达式; 增量表达式)
//{
// //循环代码
//}
for (int i = 0; i < 10; i++)
{
Console.WriteLine("这时的i为{0}",i);
}
Console.WriteLine("\n换行\n");
#endregion
#region
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 5; j++)
{
Console.WriteLine("i的值为{0},j的值为{1}", i, j);
}
}
#endregion
#region
for (; ; )//空位可填可不填
{
Console.WriteLine("这是一个死循环");
break;//用break跳出死循环
}
#endregion
#region while循环
int j = 0;
while (j < 10)
{
Console.WriteLine("j为{0}",j);
}
j=0;//重置j
for (; j < 10; )//初始表达式和增量表达式可省略
{
Console.WriteLine("j为{0}", j);
}
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+21
View File
@@ -0,0 +1,21 @@
using System;
namespace Lesson2变量
{
class classwork
{
static void Main(string[] args)
{
double num = 36.6;
Console.WriteLine(num);
string name, sex, addr;
name = "zj";
sex = "male";
addr = "jssszsgyyq";
int age = 21;
float hight = 192f, weight = 79.5f;
Console.WriteLine("年龄:" + age);
Console.WriteLine($"姓名:{name}\n年龄:{age}\n身高:{hight}体重:{weight}家庭住址:{addr}");
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,51 @@
using System;
namespace Lesson4
{
class program
{
static void Main(string[] args)
{
#region
//变量命名细则
//1不能重名
//2不能以数字开头
//3不能使用程序关键字
//4不能有特殊符号(下划线除外)
//建议的命名规则:变量名用英文,并且有变量的含义
//不建议用汉字命名
//eg重复
int i = 1;
string i = "123";
//eg数字开头
int 1i = 1;
//eg使用程序关键字(蓝色的
int string = 1;
//函数名不是关键字
int Main = 1;
//特殊符号
int re@ = 1;
//建议规则变量名用英文,并且有变量的含义
string myName = "ZJ";
#endregion
#region
//驼峰命名法,首字母小写,之后单词首字母大写
string myName = "ZXJ";
//帕斯卡命名法——所有单词首字母都大写
string MyNmae = "ZXJ";
//潜在知识点,C#对大小写敏感,myName和MyName是两个不同的变量
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+35
View File
@@ -0,0 +1,35 @@
using System;
namespace Lesson5
{
class program
{
static void Main(string[] args)
{
#region
//常量是指在程序运行过程中不会改变的值,必须初始化
//常量的定义:const 数据类型 常量名 = 值;
//常量名一般使用大写字母,多个单词之间用下划线分隔
const int MAX_VALUE = 100;
const string COMPANY_NAME = "ZJ Company";
Console.WriteLine($"最大值: {MAX_VALUE}, 公司名称: {COMPANY_NAME}");
#endregion
#region
//只读变量在定义时可以赋值,也可以在构造函数中赋值,但不能在其他地方修改
class MyClass
{
public readonly int ReadOnlyValue;
public MyClass(int value)
{
ReadOnlyValue = value;
}
}
MyClass myObject = new MyClass(42);
Console.WriteLine($"只读变量值: {myObject.ReadOnlyValue}");
//关键词 const
//固定写法:
//const 变量类型 变量名 = 值;
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+29
View File
@@ -0,0 +1,29 @@
using System;
namespace Lesson6
{
class program
{
static void Main(string[] args)
{
//什么是转义字符?
//转义字符是用来表示一些特殊字符的字符序列,通常以反斜杠(\)开头。
//例如,\n表示换行符,\t表示制表符,\"表示双引号,\\表示反斜杠本身。
//转义字符在字符串中用于表示那些不能直接输入的字符,或者需要特殊处理的字符。
//eg
Console.WriteLine("转义字符");
//固定写法 \字符
Console.WriteLine("Hello World!\n这是一个新行。");
Console.WriteLine("Hello World!\t这是一个制表符。");
Console.WriteLine("Hello World!\"这是一个双引号。\"");
Console.WriteLine("Hello World!\'这是一个单引号。\'");
Console.WriteLine("Hello World!\\这是一个反斜杠。");
Console.WriteLine("Hello World!\0这是一个空字符。");
Console.WriteLine("Hello World!\a这是一个响铃音字符。");
//知识点二
//取消转义字符
string str = @"Hello World!\n这是一个新行。";// /n不会被转义
Console.WriteLine(str);
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,13 @@
using System;
namespace Lesson7
{
class program
{
static void Main(string[] args)
{
Console.WriteLine("我是小明\n今年18岁\n我的爱好是制作游戏\n我要好好学习,天天向上");
Console.WriteLine("我是小明\n今年18岁\n我的爱好是制作游戏\n我要好好学习,天天向上");
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,156 @@
using System;
namespace Lesson7
{
class program
{
static void Main(string[] args)
{
Console.WriteLine("类型转换—隐式转换");
//什么是隐式转换?
//类型转换就是不同变量类型之间的转换
//隐式转换是指在不需要额外操作的情况下,编译器自动完成的转换。
//隐式转换规则:大范围装小范围
#region
//有符号 long->int->short->byte
long l = 1;
int i = 1;
short s = 1;
sbyte sb = 1;
l = i; //int 转 long
//i = l; long 转 int
//小的类型不能装大的 需要强制转换,不能隐式转换
//可以的转换:
l = i;
l = s;
l = sb;
i = s;
s = sb;
//无符号 ulong->uint->ushort->byte
ulong ul = 1;
uint ui = 1;
ushort us = 1;
byte b = 1;
//浮点数 double float decimal
decimal de = 1.1m;
double d = 1.1;
float f = 1.1f;
//decimal没有办法用隐式转换的形式去存储double和float
//de = d;
//de = f;
d = f;//float 是可以转 double 的
//特殊类型 bool char string
//他们之间不存在隐式转换
bool b1 = true;
char c = 'a';
string str = "Hello World";
#endregion
#region
#region
// 无符号
byte b2 = 1;
ushort us2 = 1;
uint ui2 = 1;
ulong ul2 = 1;
// 有符号
sbyte sb2 = 1;
short s2 = 1;
int i2 = 1;
long l2 = 1;
// 无符号装有符号
// 有符号的变量无法隐式转换为无符号的变量 eg:负数情况
//b2 = sb2;
//us2 = sb2;
// 有符号装无符号
// 无符号的变量可以隐式转换为有符号的变量
// 但需要注意的是,如果无符号变量的值大于有符号变量的最大值,则会发生溢出
//i2 = ui2;
i2 = b2;
#endregion
#region
// 浮点数装整数
float f2 = 1.1f;
double d2 = 1.1;
decimal de2 = 1.1m;
//浮点数可以装载任何类型的整数(有符号、无符号)
f2 = l2;
f2 = ul2;
f2 = 1000000000000000000; // 1.0E+20
Console.WriteLine(f2); // 输出 1.0E+20
//decimal不能隐式存储浮点数
//但是可以隐式存储整数
de = l2;
de = ul2;
//double->float->所有整形
//decimal->所有整形
//整数是不能隐式存储浮点数的,因为浮点数有小数部分
//i2 = f2; // 错误,不能隐式转换
#endregion
#region
// bool
//bool bo2 = true;
//bo2 = i2;
//bo2 = ui2;
//bo2 = f2;
//i2 = bo2;
//ui2 = bo2;
//bool无法与其他类型隐式转换
// char
char c2 = 'a';
//c2 = i2;
//c2 = ui2;
//c2 = f2;
//c2 = str;
//char 可以隐式转换为 整数类型 和 浮点型
//char转换后的值是其对应的ASCII编码值
i2 = c2;
Console.WriteLine(i2);
f2 = c2;
Console.WriteLine(f2);
ui2 = c2;
Console.WriteLine(ui2);
//str = c2;
// string
#endregion
#endregion
//总结:
//隐式转换是编译器自动完成的转换,不需要额外操作。
//隐式转换规则:大范围装小范围,高精度装低精度
//double->float->所有整形->char
//decimal不能隐式转换为浮点数,但可以隐式转换为整数。
//decimal->所有整形->char
//bool、string不参与隐式转换。
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,28 @@
using System;
namespace Lesson8
{
class program
{
static void Main(string[] args)
{
int num1 = 24069;
Console.WriteLine(Convert.ToChar(num1));
Console.WriteLine();
int shuXue, yuWen, yingYu;
string name;
Console.Write("请输入姓名:");
name = Console.ReadLine();
Console.Write("请输入数学成绩:");
shuXue = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入语文成绩:");
yuWen = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入英语成绩:");
yingYu = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"你的成绩如下:\n语文:{yuWen}\n数学:{shuXue}\n英语:{yingYu}");
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+177
View File
@@ -0,0 +1,177 @@
using System;
namespace Lesson8
{
class program
{
static void Main(string[] args)
{
Console.WriteLine("显式转换");
// 显式转换=手动处理 强制转换
#region
//作用:一般情况下,将高精度类型转换为低精度类型
//语法:变量类型 变量名 = (目标类型)变量名;
//注意:类型不兼容 精度问题 范围问题
//相同大类的整形
//有符号整形
sbyte sb = 1;
short s = 1;
int i = 40000;
long l = 1;
//s = i; //错误:类型不兼容
i = (int)l; //正确:手动转换
Console.WriteLine(i);
s = (short)i;//正确但注意:超过了short的范围
Console.WriteLine(s);
//无符号整形
byte b = 1;
ushort us = 1;
uint ui = 1;
ulong ul = 1;
ui = (uint)ul; //正确:手动转换
Console.WriteLine(ui);
//浮点数
float f = 1.0f;
double d = 1.123456789012345;
f = (float)d; //正确:手动转换
Console.WriteLine(f);//注意:精度损失
//无符号和有符号之间的转换
uint ui2 = 1;
int i2 = 1;
//ui2 = i2; //错误:类型不兼容
ui2 = (uint)i2; //正确:手动转换
Console.WriteLine(ui2);
i2 = -1; //负数
ui2 = (uint)i2;
Console.WriteLine(ui2); //注意:负数转换为无符号整形时,结果是一个很大的数
//浮点数和整形之间的转换,会直接截断小数部分
i2 = (int)1.2f;
Console.WriteLine(i2); //注意:小数部分被截断
//char和数值类型
char c = 'A'; //字符'A'的ASCII码是65
Console.WriteLine(c);
int asciiValue = (int)c; //将字符转换为ASCII码
Console.WriteLine(asciiValue);
//bool和string之间的转换,不能通过括号强转
bool bo = true;
//int i3 = (bool)bo; 错误:bool不能直接转换为int
string str = "123";
//i3 = int(str); 错误:string不能直接转换为int
#endregion
#region Parse方法
//作用:将字符串转换为其他类型
//语法:目标类型. Parse(字符串变量名);
//注意:如果字符串格式不正确,会抛出异常,必须是能够转换的类型
//有符号
string str2 = "123";
int i3 = int.Parse(str2); //正确:字符串转换为整数
Console.WriteLine(i3);
//i3 = int.Parse("fds"); 错误:字符串格式不正确,不是能够转换的类型,会抛出异常
//Console.WriteLine(i3);
short s3 = short.Parse("4");//正确:字符串转换为短整数
Console.WriteLine(s3);
//s3 = short.Parse("40000"); 错误:字符串格式不正确,超出了short的范围,会抛出异常
//Console.WriteLine(s3);
//无符号
//规则相同
Console.WriteLine(byte.Parse("1"));
Console.WriteLine(ushort.Parse("2"));
Console.WriteLine(uint.Parse("3"));
Console.WriteLine(ulong.Parse("4"));
//浮点数
double f3 = double.Parse("1.23456789"); //正确:字符串转换为双精度浮点数
Console.WriteLine(f3);
float f4 = float.Parse("1.23456789"); //正确:字符串转换为单精度浮点数
Console.WriteLine(f4);
//特殊类型
bool bo2 = bool.Parse("true"); //正确:字符串转换为布尔值
Console.WriteLine(bo2);
//char c3 = char.Parse(bo2); 错误:bool不能直接转换为char
//string str3 = string.Parse(bo2); 错误:bool不能直接转换为string
char c2 = char.Parse("A"); //正确:字符串转换为字符
Console.WriteLine(c2);
#endregion
#region Convert方法
//作用:更准确的将不同类型之间进行转换,支持更多类型的转换
//语法:Convert.To目标类型(变量名);
//注意:如果转换失败,会返回默认值,不会抛出异常
//转换字符串
int a = Convert.ToInt32("123"); //正确:字符串转换为整数
Console.WriteLine(a);
//a = Convert.ToInt32("fds"); 错误:字符串格式不正确,不是能够转换的类型,会抛出异常
a = Convert.ToInt32('A'); //正确:字符'A'的ASCII码是65
Console.WriteLine(a);
//精度更准确
a = Convert.ToInt32(1.5f); //正确:数字转换为int,会四舍五入
Console.WriteLine(a);
//特殊类型转换
a = Convert.ToInt32(true); //正确:bool转换为inttrue为1false为0
Console.WriteLine(a);
//每一个类型都有对应的Convert方法
short s4 = Convert.ToInt16("123"); //正确:字符串转换为短整数
uint ui3 = Convert.ToUInt32("123"); //正确:字符串转换为无符号整数
long s5 = Convert.ToInt64("123456789"); //正确:字符串转换为长整数
sbyte sb5 = Convert.ToSByte("123"); //正确:字符串转换为有符号字节
float f5 = Convert.ToSingle("1.23456789"); //正确:字符串转换为单精度浮点数
double d5 = Convert.ToDouble("1.23456789"); //正确:字符串转换为双精度浮点数
decimal dec = Convert.ToDecimal("1.23456789"); //正确:字符串转换为十进制数
bool bo3 = Convert.ToBoolean("true"); //正确:字符串转换为布尔值
#endregion
#region string
//作用:将其他类型转换为字符串,拼接打印
//语法:变量名.ToString();
string str6 = 1.ToString();
Console.WriteLine(str6);
str6 = true.ToString();
Console.WriteLine(str6);
str6 = 1.23456789f.ToString();
Console.WriteLine(str6);
str6 = 'A'.ToString();
Console.WriteLine(str6);
//拼接
Console.WriteLine("拼接后的字符串"+1+true);//1和true会被转换为字符串,结果是"1True"
//eg:
str6 = "123" + 1 + true + 1.254;//默认调用了ToString()方法
Console.WriteLine(str6);
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+52
View File
@@ -0,0 +1,52 @@
using System;
namespace Lesson8
{
class program
{
static void Main(string[] args)
{
Console.WriteLine("异常捕获");
//作用:解决程序运行时的异常问题,避免卡死或崩溃
#region
//基本语法:try{}catch{}尝试执行代码块中的代码,如果没有异常则继续执行
try
{
//可能会发生异常的代码块
}
catch(Exception e)//(Exception e)是可选项,e是异常对象,可以获取异常信息
{
//捕获异常的代码块
}
//可选部分:finally{}在try或catch执行完后执行的代码块,无论是否有异常都会执行
finally
{
//清理资源或执行收尾工作
}
//注意:异常捕获代码基本结构中,不需要加; 只有里面的代码需要加;
#endregion
#region /
//示例:除数不能为0的异常捕获
try
{
Console.WriteLine("请输入一个整数:");
string str = Console.ReadLine();
int i = int.Parse(str);
Console.WriteLine("你输入了:" + i);
}
catch
{
Console.WriteLine("只能输入整数,请重新输入!");
}
finally
{
Console.WriteLine("程序执行完毕。");
}
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,50 @@
using System;
namespace Lesson8
{
class program
{
static void Main(string[] args)
{
#region
try
{
Console.Write("请输入一个数字:");
int num = int.Parse(Console.ReadLine());
Console.WriteLine($"你输入的数字是: {num}");
}
catch
{
Console.WriteLine("请你输入一个数字");
}
finally
{
Console.WriteLine("程序执行完毕!");
}
#endregion
#region
try
{
int yuWen, shuXue, yingYu;
Console.Write("请你输入你的名字:");
string name = Console.ReadLine();
Console.Write("请你输入你的语文成绩:");
yuWen = int.Parse(Console.ReadLine());
Console.Write("请你输入你的数学成绩:");
shuXue = int.Parse(Console.ReadLine());
Console.Write("请你输入你的英语成绩:");
yingYu = int.Parse(Console.ReadLine());
Console.WriteLine($"你的语文成绩是:{yuWen},你的数学成绩是{shuXue},你的英语成绩是:{yingYu}.");
}
catch
{
Console.WriteLine("成绩录入时发生了错误");
}
finally
{
Console.WriteLine("成绩录入完毕!");
}
#endregion
}
}
}
@@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36408.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "必备知识点_控制台相关", "必备知识点_控制台相关\必备知识点_控制台相关.csproj", "{06573DDE-AC71-42D8-98CA-98DD42A3C236}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "控制台相关练习题", "练习题\控制台相关练习题.csproj", "{88D217C8-8B85-4719-98E2-3A8FAF8489A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "随机数", "随机数\随机数.csproj", "{A2D7438B-0455-43FA-A8E0-ED830E1DD30B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "随机数相关练习题", "随机数相关练习题\随机数相关练习题.csproj", "{1D204805-9EFC-4157-AA4F-A16BBD9CD95A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "小游戏", "小游戏\小游戏.csproj", "{7DD928E2-3B86-4EDB-92BB-E53BF3D0D069}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{06573DDE-AC71-42D8-98CA-98DD42A3C236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06573DDE-AC71-42D8-98CA-98DD42A3C236}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06573DDE-AC71-42D8-98CA-98DD42A3C236}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06573DDE-AC71-42D8-98CA-98DD42A3C236}.Release|Any CPU.Build.0 = Release|Any CPU
{88D217C8-8B85-4719-98E2-3A8FAF8489A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88D217C8-8B85-4719-98E2-3A8FAF8489A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88D217C8-8B85-4719-98E2-3A8FAF8489A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88D217C8-8B85-4719-98E2-3A8FAF8489A3}.Release|Any CPU.Build.0 = Release|Any CPU
{A2D7438B-0455-43FA-A8E0-ED830E1DD30B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2D7438B-0455-43FA-A8E0-ED830E1DD30B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2D7438B-0455-43FA-A8E0-ED830E1DD30B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2D7438B-0455-43FA-A8E0-ED830E1DD30B}.Release|Any CPU.Build.0 = Release|Any CPU
{1D204805-9EFC-4157-AA4F-A16BBD9CD95A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D204805-9EFC-4157-AA4F-A16BBD9CD95A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D204805-9EFC-4157-AA4F-A16BBD9CD95A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D204805-9EFC-4157-AA4F-A16BBD9CD95A}.Release|Any CPU.Build.0 = Release|Any CPU
{7DD928E2-3B86-4EDB-92BB-E53BF3D0D069}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7DD928E2-3B86-4EDB-92BB-E53BF3D0D069}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DD928E2-3B86-4EDB-92BB-E53BF3D0D069}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DD928E2-3B86-4EDB-92BB-E53BF3D0D069}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93EA734C-376F-48C2-9A20-13FCCD3D81DB}
EndGlobalSection
EndGlobal
+370
View File
@@ -0,0 +1,370 @@
#region
using System.ComponentModel.Design;
Console.BackgroundColor = ConsoleColor.Black;
Console.Clear();
int w = 50;
int h = 30;
Console.SetWindowSize(w, h);
Console.SetBufferSize(w, h);
Console.CursorVisible = false;
#endregion
#region
int nowScene = 1;
try
{
while (true)
{
switch (nowScene)
{
//主界面
case 1:
Console.Clear();
Console.WriteLine("开始场景");
Console.ForegroundColor = ConsoleColor.White;
Console.SetCursorPosition(w / 2 - 3, h / 4);
Console.Write("寄掰游戏");
bool notExit = true;
int nowSceneIndex = 1;
char choice = 'w';
nowScene = 2;
while (notExit)
{
Console.SetCursorPosition(w / 2 - 3, h / 3 + 1);
Console.ForegroundColor = nowSceneIndex == 1 ? ConsoleColor.Red : ConsoleColor.White;
Console.Write("开始游戏");
Console.ForegroundColor = nowSceneIndex == 0 ? ConsoleColor.Red : ConsoleColor.White;
Console.SetCursorPosition(w / 2 - 3, h / 3 + 3);
Console.Write("退出游戏");
choice = Console.ReadKey(true).KeyChar;
switch (choice)
{
case '↑':
case 'w':
case 'W':
nowScene = 2;
nowSceneIndex = 1;
break;
case '↓':
case 's':
case 'S':
nowSceneIndex = 0;
nowScene = 3;
break;
case '\r':
notExit = false;
break;
}
}
break;
//游戏场景
case 2:
#region
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("游戏场景");
Console.SetCursorPosition(2, h - 5);
Console.Write("1.WASD移动 2.靠近BOSS按J攻击");
#region
Console.ForegroundColor = ConsoleColor.Red;
for (int i = 0; i < w; i += 2)
{
for (int j = 0; j < h; j++)
{
//Console.SetCursorPosition(25, 12);
//Console.WriteLine("当前i{0},j{1}", i, j);//测试用
if (i == 0 || j == 0)
{
Console.SetCursorPosition(i, j);
Console.Write("■");
}
else if (j == Console.BufferHeight - 6)
{
Console.SetCursorPosition(i, j);
Console.Write("■");
}
else if (i == Console.BufferWidth - 2 || j == Console.BufferHeight - 1)
{
Console.SetCursorPosition(i, j);
Console.Write("■");
}
}
}
#endregion
#endregion
#region
Random r = new Random();
notExit = true;
bool isBossDefeated = false;
bool isPlayerAlive = true;
bool isPlayerApproaching = false;
char movement;
//BOSS参数
string bossIcon = "■";
int bossHP = 100;
int bossAttackMax = 120;
int bossAttackMin = 100;
int bossDefense = 5;
int bossLocationX = r.Next(2, w - 2);
int bossLocationY = r.Next(1, h - 7);
while (bossLocationX < 2 || bossLocationY < 2 || bossLocationX > w - 4 || bossLocationY > h - 8)
{
bossLocationX = r.Next(2, w - 2);
bossLocationY = r.Next(1, h - 7);
}
//玩家参数
string playerIcon = "●";
int playerHP = 100;
int playerAttackMax = 12;
int playerAttackMin = 7;
int playerLocationX = r.Next(2, w - 2);
int playerLocationY = r.Next(1, h - 7);
while (playerLocationX == bossLocationX && playerLocationY == bossLocationY)
{
playerLocationX = r.Next(2, w - 2);
playerLocationY = r.Next(1, h - 7);
}
#endregion
while (notExit)
{
#region
if (playerHP > 0)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(playerLocationX, playerLocationY);
Console.WriteLine(playerIcon);
}
#endregion
#region BOSS
if (bossHP > 0)
{
Console.SetCursorPosition(bossLocationX, bossLocationY);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(bossIcon);
}
#endregion
#region BOSS位置
if (playerLocationY == bossLocationY && playerLocationX == bossLocationX ||
playerLocationY == bossLocationY && playerLocationX == bossLocationX - 1 ||
playerLocationY == bossLocationY && playerLocationX == bossLocationX + 1)
{
isPlayerApproaching = true;
while (isPlayerAlive)
{
Console.SetCursorPosition(2, h - 4);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Press J to join fight!");
movement = Console.ReadKey(true).KeyChar;
if (movement == 'J' || movement == 'j')
{
int round = 1;
bool isDefend = false;
int damage;
#region
Console.SetCursorPosition(2, h - 4);
Console.WriteLine(" ");
Console.SetCursorPosition(2, h - 4);
Console.WriteLine("Combat start!");
Thread.Sleep(2000);
Console.SetCursorPosition(2, h - 4);
Console.WriteLine(" ");
#endregion
while (isPlayerAlive)
{
damage = 0;
Console.SetCursorPosition(2, h - 5);
Console.WriteLine(" ");
if (bossHP <= 0)
{
isBossDefeated = true;
Console.SetCursorPosition(2, h - 5);
Console.WriteLine("你击败了BOSS,按下任何按键继续");
Thread.Sleep(1000);
isBossDefeated = true;
notExit = true;
nowScene = 3;
break;
}
if (playerHP <= 0)
{
isPlayerAlive = false;
Console.SetCursorPosition(2, h - 5);
Console.WriteLine("你被BOSS打败了,按下任何按键继续");
Thread.Sleep(1000);
notExit = true;
nowScene = 3;
break;
}
if (round % 2 != 0)
{
Console.SetCursorPosition(2, h - 5);
Console.WriteLine("现在是你的回合,按下1防御,按下2攻击");
movement = Console.ReadKey(true).KeyChar;
if (movement == '1')
{
isDefend = true;
Console.SetCursorPosition(2, h - 5);
Console.WriteLine("你选择了防御");
Thread.Sleep(2000);
}
else if (movement == '2')
{
isDefend = false;
damage = r.Next(playerAttackMin, playerAttackMax);
bossHP -= damage;
Console.SetCursorPosition(2, h - 4);
Console.WriteLine("你攻击了BOSS,造成了{0}点伤害,BOSS剩余血量{1}", damage, bossHP);
Thread.Sleep(2000);
}
}
else
{
Console.SetCursorPosition(2, h - 5);
Console.WriteLine("现在是BOSS的回合");
Thread.Sleep(2000);
if (isDefend = false)
{
damage = r.Next(bossAttackMin, bossAttackMax);
playerHP -= damage;
Console.SetCursorPosition(2, h - 4);
Console.WriteLine("boss攻击了你{0}点血,剩余{1}点血",damage,playerHP);
Thread.Sleep(2400);
}
else
{
damage = r.Next(bossAttackMin, bossAttackMax) / 2; //防御时伤害减半
playerHP -= damage;
Console.SetCursorPosition(2, h - 4);
Console.WriteLine("boss攻击了你{0}点血,剩余{1}点血", damage, playerHP);
Thread.Sleep(2500);
}
}
round++;
}
if (isBossDefeated)
{
notExit = false; //退出游戏场景
nowScene = 3; //进入结算场景
break;
}
}
else
{
Console.SetCursorPosition(2, h - 4);
Console.WriteLine(" ");
break;
}
notExit = false; //退出游戏场景
nowScene = 3; //进入结算场景
break;
}
}
#endregion
#region
movement = Console.ReadKey(true).KeyChar;
//test
Console.SetCursorPosition(2, h - 2);
Console.WriteLine(movement);
#region
Console.SetCursorPosition(playerLocationX, playerLocationY);
Console.WriteLine(" ");
#endregion
switch (movement)
{
case 'w':
case 'W':
if (playerLocationY > 1)
{
playerLocationY--;
}
break;
case 's':
case 'S':
if (playerLocationY < h - 7)
{
playerLocationY++;
}
break;
case 'a':
case 'A':
if (playerLocationX > 2)
{
playerLocationX -= 1;
}
break;
case 'd':
case 'D':
if (playerLocationX < w - 4)
{
playerLocationX += 1;
}
break;
case 'j':
case 'J':
if (isPlayerApproaching == false)
{
Console.SetCursorPosition(2, h - 4);
Console.WriteLine("距离不足");
}
break;
case 'q':
case 'Q':
nowScene = 3; //退出游戏
break;
}
#endregion
#region
if (nowScene == 3)
{
notExit = false;
break;
}
#endregion
}
break;
//结算场景
case 3:
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("结算场景");
//Console.WriteLine("恭喜你,成功营救公主!");
Console.WriteLine("Press any key to quit");
int block = Console.ReadKey(true).KeyChar;
Environment.Exit(0);
break;
}
}
}
catch (Exception e)
{
Console.WriteLine("Error code:{0}",e);
}
finally
{
Console.ResetColor(); //重置颜色为默认颜色
Console.Clear(); //清空控制台内容
Environment.Exit(0);
}
#endregion
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,70 @@
using System;
namespace _控制台相关
{
class Program
{
static void Main(string[] args)
{
#region
// 输出
Console.WriteLine("123");//输出后换行
Console.Write("456");//输出后不换行
// 输入
string str = Console.ReadLine(); //读取一行输入
char c = Console.ReadKey(/*这里加true不会将输入的内容显示在控制台上*/).KeyChar;//读取一个按键输入
#endregion
#region
//1.清空
Console.Clear(); //清空控制台内容
//2.设置控制台大小
//2.1 设置控制台窗口大小
Console.SetWindowSize(1000, 500); //设置控制台窗口大小为100列,50行
//2.2 设置控制台缓冲区大小
Console.SetBufferSize(1000, 500); //设置控制台缓冲区大小为200列,100行
//注意:
//1.先设置窗口大小,再设置缓冲区大小,否则可能会报错。
//2.缓冲区大小必须大于等于窗口大小,否则会报错。
//3.窗口的大小不能超过屏幕的大小,否则会报错。
//3.设置光标位置
//控制台左上角为(0,0),右下角为(控制台宽度-1, 控制台高度-1)
Console.SetCursorPosition(10, 10); //设置光标位置为(10,10)
Console.WriteLine("123");
//注意:
//1.光标位置不能超过控制台的大小,否则会报错。
//2.横纵距离单位不同,视觉上大约1y=2x
//4.设置颜色
//4.1 设置文字颜色(前景色)
Console.ForegroundColor = ConsoleColor.Red; //设置文字颜色为红色
//4.2 设置背景颜色
Console.BackgroundColor = ConsoleColor.Blue; //设置背景颜色为蓝色
Console.WriteLine("现在是红色文字,蓝色背景");
//4.3 重置颜色
Console.ResetColor(); //重置颜色为默认颜色
Console.Clear(); //重置后要清空控制台内容,否则颜色不会改变
Console.WriteLine("现在是默认颜色文字,默认背景");
//5.光标显影
Console.CursorVisible = false; //设置光标不可见
//注意:设置光标不可见后,光标位置仍然可以通过SetCursorPosition方法设置,但不会显示出来。
//6.关闭控制台
Environment.Exit(0); //退出程序,参数为退出码,0表示正常退出,非0表示异常退出
//注意:在调试模式时,不会自动关闭,在exe中才能体现。
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+68
View File
@@ -0,0 +1,68 @@
Console.ForegroundColor = ConsoleColor.Yellow; //设置文字颜色为绿色
Console.BackgroundColor = ConsoleColor.Red; //设置背景颜色为黑色
Console.SetWindowSize(50, 25);
Console.SetBufferSize(50, 25);
Console.CursorVisible = false;
try
{
char dis;
int x=0, y=0;
while (true)
{
Console.Clear();
Console.SetCursorPosition(x, y);
Console.Write("■");
dis = Console.ReadKey(true).KeyChar;
switch (dis)
{
case 'w':
case 'W':
y--;
if (y < 0)
{
y = 0; //防止光标位置小于0
}
break;
case 'a':
case 'A':
x -= 2;
if (x < 0)
{
x = 0; //防止光标位置小于0
}
break;
case 's':
case 'S':
y++;
if (y > Console.BufferHeight - 1)
{
y = Console.BufferHeight - 1; //防止光标位置超过缓冲区高度
}
break;
case 'd':
case 'D':
x += 2;
if ( x > Console.BufferWidth - 2)
{
x = Console.BufferWidth - 2;
}
break;
}
}
}catch (Exception ex)
{
Console.WriteLine($"发生异常: {ex.Message}");
}
finally
{
Console.ResetColor(); //重置颜色为默认颜色
Console.Clear(); //清空控制台内容
Console.WriteLine("程序结束");
Environment.Exit(0);
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+24
View File
@@ -0,0 +1,24 @@
using System;
namespace
{
class Program
{
static void Main(string[] args)
{
#region
//固定写法
// Random 关键字
Random r = new Random();
#endregion
#region
int i = r.Next(); //生成一个非负随机整数
Console.WriteLine(i);
i = r.Next(100); //生成一个非负随机整数,范围为[0, 100)
Console.WriteLine(i);
i = r.Next(50, 100); //生成一个非负随机整数,范围为[50, 100)
Console.WriteLine(i);
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,34 @@
Random r = new Random();
int bossHealth = 20;
int bossDefense = 10;
int round = 1;
try
{
Console.WriteLine("游戏开始");
while (true)
{
int attack = r.Next(8, 13);
Console.WriteLine("当前第{0}回合",round);
if (attack >= bossDefense)
{
bossHealth -= attack - bossDefense;
Console.WriteLine("你攻击了BOSS,造成了" + attack + "点伤害\n" + "BOSS剩余血量:" + bossHealth);
}else
{
Console.WriteLine("你的攻击被BOSS防御住了,造成了0点伤害");
}
round++;
if (bossHealth <= 0)
{
Console.WriteLine("你打赢了BOSS,共使用了{0}回合",round-1);
break;
}
}
}catch (Exception ex)
{
Console.WriteLine("错误代码: " + ex.Message);
}
finally
{
Console.WriteLine("游戏结束");
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+175
View File
@@ -0,0 +1,175 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36408.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{27B93A9C-0FF2-4DCD-B0B3-D3C2ABE36381}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson1_枚举", "Lesson1_枚举\Lesson1_枚举.csproj", "{1131C91A-8FF6-48E1-B1BF-165650F15D05}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson1_ 枚举练习", "Lesson1_ 枚举练习\Lesson1_ 枚举练习.csproj", "{51244337-7936-4557-9192-773876FACD3D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson2_一维数组", "Lesson2_一维数组\Lesson2_一维数组.csproj", "{2C6D3608-AA58-46D1-BF36-C647495915A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson2_一维数组练习", "Lesson2_数组练习\Lesson2_一维数组练习.csproj", "{BAA139CE-93A7-4E95-AF05-1BD376B19F2C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson3_二维数组", "Lesson3_二维数组\Lesson3_二维数组.csproj", "{C521F9D9-D58F-40F8-B5B7-67E7FC6B0433}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson3_二维数组练习题", "Lesson3_二维数组练习题\Lesson3_二维数组练习题.csproj", "{79F5FDB5-6653-446B-B56F-DF5812047233}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson4_交错数组", "Lesson4_交错数组\Lesson4_交错数组.csproj", "{46659CA6-5C9D-466C-9F85-BFECD7A5DA7D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson5_值类型和引用类型", "Lesson5_值类型和引用类型\Lesson5_值类型和引用类型.csproj", "{A2FB3021-8D7C-4422-B65E-C8295C9D46B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson6_特殊的引用类型string", "Lesson6_特殊的引用类型string\Lesson6_特殊的引用类型string.csproj", "{34CEE0D5-059E-41F3-B315-80F74F671CB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson7_函数", "Lesson7_函数\Lesson7_函数.csproj", "{9BA8FD2E-8265-4346-8AD3-4E3C1A0E539F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson7_函数练习", "Lesson7_函数练习\Lesson7_函数练习.csproj", "{107DF984-2089-4E81-91E1-C2D8D0BD75F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson8_ref和out", "Lesson8_ref和out\Lesson8_ref和out.csproj", "{D626A1F8-B072-4DC2-B6BE-98A1B9BC9761}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson8_ref和out练习", "Lesson8_ref和out练习\Lesson8_ref和out练习.csproj", "{DB7E47D3-E121-4EC6-8B0E-9F436217D228}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson9_变长参数和参数默认值", "Lesson9_变长参数和参数默认值\Lesson9_变长参数和参数默认值.csproj", "{7FF87EE5-8F53-404C-BB4E-14151D411519}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson9_变长参数和参数默认值练习", "Lesson9_变长参数和参数默认值练习\Lesson9_变长参数和参数默认值练习.csproj", "{7957688A-3355-48DD-8C9F-7EEE91B66400}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson10_函数重载", "Lesson10_函数重载\Lesson10_函数重载.csproj", "{202E2B5E-DBC6-4100-9651-B6AC520A4CF5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson10_函数重载练习", "Lesson10_函数重载练习\Lesson10_函数重载练习.csproj", "{76A13792-153D-4D51-9ACA-B8B12000EFAF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson11_递归函数", "Lesson11_递归函数\Lesson11_递归函数.csproj", "{15F9E2CA-5E65-4147-BE9B-7563353B9676}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson11_递归函数练习", "Lesson11_递归函数练习\Lesson11_递归函数练习.csproj", "{F25A3D9E-3C4E-4984-9910-DBF14EEB4113}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson12_结构体", "Lesson12_结构体\Lesson12_结构体.csproj", "{49507514-25F2-453E-BBC3-57E1AA694B9B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson12_结构体练习", "Lesson12_结构体练习\Lesson12_结构体练习.csproj", "{C6E420B1-EE2F-4517-9952-FBEDC9C7BA43}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson13_冒泡排序", "Lesson13_冒泡排序\Lesson13_冒泡排序.csproj", "{68510D96-BECD-4B48-84B6-8D17975A74AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson13_冒泡排序练习", "Lesson13_冒泡排序练习\Lesson13_冒泡排序练习.csproj", "{58DE0727-D9EB-4F96-95D8-54F275449649}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson14_选择排序", "Lesson14_选择排序\Lesson14_选择排序.csproj", "{A0279ACE-B0A8-43C9-86B8-D45B0A25BF24}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson14_选择排序练习", "Lesson14_选择排序练习\Lesson14_选择排序练习.csproj", "{D0B92715-B833-4513-AE97-C20101437297}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{27B93A9C-0FF2-4DCD-B0B3-D3C2ABE36381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27B93A9C-0FF2-4DCD-B0B3-D3C2ABE36381}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27B93A9C-0FF2-4DCD-B0B3-D3C2ABE36381}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27B93A9C-0FF2-4DCD-B0B3-D3C2ABE36381}.Release|Any CPU.Build.0 = Release|Any CPU
{1131C91A-8FF6-48E1-B1BF-165650F15D05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1131C91A-8FF6-48E1-B1BF-165650F15D05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1131C91A-8FF6-48E1-B1BF-165650F15D05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1131C91A-8FF6-48E1-B1BF-165650F15D05}.Release|Any CPU.Build.0 = Release|Any CPU
{51244337-7936-4557-9192-773876FACD3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51244337-7936-4557-9192-773876FACD3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51244337-7936-4557-9192-773876FACD3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51244337-7936-4557-9192-773876FACD3D}.Release|Any CPU.Build.0 = Release|Any CPU
{2C6D3608-AA58-46D1-BF36-C647495915A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C6D3608-AA58-46D1-BF36-C647495915A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C6D3608-AA58-46D1-BF36-C647495915A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C6D3608-AA58-46D1-BF36-C647495915A8}.Release|Any CPU.Build.0 = Release|Any CPU
{BAA139CE-93A7-4E95-AF05-1BD376B19F2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAA139CE-93A7-4E95-AF05-1BD376B19F2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAA139CE-93A7-4E95-AF05-1BD376B19F2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAA139CE-93A7-4E95-AF05-1BD376B19F2C}.Release|Any CPU.Build.0 = Release|Any CPU
{C521F9D9-D58F-40F8-B5B7-67E7FC6B0433}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C521F9D9-D58F-40F8-B5B7-67E7FC6B0433}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C521F9D9-D58F-40F8-B5B7-67E7FC6B0433}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C521F9D9-D58F-40F8-B5B7-67E7FC6B0433}.Release|Any CPU.Build.0 = Release|Any CPU
{79F5FDB5-6653-446B-B56F-DF5812047233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79F5FDB5-6653-446B-B56F-DF5812047233}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79F5FDB5-6653-446B-B56F-DF5812047233}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79F5FDB5-6653-446B-B56F-DF5812047233}.Release|Any CPU.Build.0 = Release|Any CPU
{46659CA6-5C9D-466C-9F85-BFECD7A5DA7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46659CA6-5C9D-466C-9F85-BFECD7A5DA7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46659CA6-5C9D-466C-9F85-BFECD7A5DA7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46659CA6-5C9D-466C-9F85-BFECD7A5DA7D}.Release|Any CPU.Build.0 = Release|Any CPU
{A2FB3021-8D7C-4422-B65E-C8295C9D46B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2FB3021-8D7C-4422-B65E-C8295C9D46B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2FB3021-8D7C-4422-B65E-C8295C9D46B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2FB3021-8D7C-4422-B65E-C8295C9D46B3}.Release|Any CPU.Build.0 = Release|Any CPU
{34CEE0D5-059E-41F3-B315-80F74F671CB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34CEE0D5-059E-41F3-B315-80F74F671CB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34CEE0D5-059E-41F3-B315-80F74F671CB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34CEE0D5-059E-41F3-B315-80F74F671CB1}.Release|Any CPU.Build.0 = Release|Any CPU
{9BA8FD2E-8265-4346-8AD3-4E3C1A0E539F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9BA8FD2E-8265-4346-8AD3-4E3C1A0E539F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BA8FD2E-8265-4346-8AD3-4E3C1A0E539F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BA8FD2E-8265-4346-8AD3-4E3C1A0E539F}.Release|Any CPU.Build.0 = Release|Any CPU
{107DF984-2089-4E81-91E1-C2D8D0BD75F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{107DF984-2089-4E81-91E1-C2D8D0BD75F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{107DF984-2089-4E81-91E1-C2D8D0BD75F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{107DF984-2089-4E81-91E1-C2D8D0BD75F6}.Release|Any CPU.Build.0 = Release|Any CPU
{D626A1F8-B072-4DC2-B6BE-98A1B9BC9761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D626A1F8-B072-4DC2-B6BE-98A1B9BC9761}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D626A1F8-B072-4DC2-B6BE-98A1B9BC9761}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D626A1F8-B072-4DC2-B6BE-98A1B9BC9761}.Release|Any CPU.Build.0 = Release|Any CPU
{DB7E47D3-E121-4EC6-8B0E-9F436217D228}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB7E47D3-E121-4EC6-8B0E-9F436217D228}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB7E47D3-E121-4EC6-8B0E-9F436217D228}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB7E47D3-E121-4EC6-8B0E-9F436217D228}.Release|Any CPU.Build.0 = Release|Any CPU
{7FF87EE5-8F53-404C-BB4E-14151D411519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7FF87EE5-8F53-404C-BB4E-14151D411519}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7FF87EE5-8F53-404C-BB4E-14151D411519}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FF87EE5-8F53-404C-BB4E-14151D411519}.Release|Any CPU.Build.0 = Release|Any CPU
{7957688A-3355-48DD-8C9F-7EEE91B66400}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7957688A-3355-48DD-8C9F-7EEE91B66400}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7957688A-3355-48DD-8C9F-7EEE91B66400}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7957688A-3355-48DD-8C9F-7EEE91B66400}.Release|Any CPU.Build.0 = Release|Any CPU
{202E2B5E-DBC6-4100-9651-B6AC520A4CF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{202E2B5E-DBC6-4100-9651-B6AC520A4CF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{202E2B5E-DBC6-4100-9651-B6AC520A4CF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{202E2B5E-DBC6-4100-9651-B6AC520A4CF5}.Release|Any CPU.Build.0 = Release|Any CPU
{76A13792-153D-4D51-9ACA-B8B12000EFAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76A13792-153D-4D51-9ACA-B8B12000EFAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76A13792-153D-4D51-9ACA-B8B12000EFAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76A13792-153D-4D51-9ACA-B8B12000EFAF}.Release|Any CPU.Build.0 = Release|Any CPU
{15F9E2CA-5E65-4147-BE9B-7563353B9676}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15F9E2CA-5E65-4147-BE9B-7563353B9676}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15F9E2CA-5E65-4147-BE9B-7563353B9676}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15F9E2CA-5E65-4147-BE9B-7563353B9676}.Release|Any CPU.Build.0 = Release|Any CPU
{F25A3D9E-3C4E-4984-9910-DBF14EEB4113}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F25A3D9E-3C4E-4984-9910-DBF14EEB4113}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F25A3D9E-3C4E-4984-9910-DBF14EEB4113}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F25A3D9E-3C4E-4984-9910-DBF14EEB4113}.Release|Any CPU.Build.0 = Release|Any CPU
{49507514-25F2-453E-BBC3-57E1AA694B9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49507514-25F2-453E-BBC3-57E1AA694B9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49507514-25F2-453E-BBC3-57E1AA694B9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49507514-25F2-453E-BBC3-57E1AA694B9B}.Release|Any CPU.Build.0 = Release|Any CPU
{C6E420B1-EE2F-4517-9952-FBEDC9C7BA43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6E420B1-EE2F-4517-9952-FBEDC9C7BA43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6E420B1-EE2F-4517-9952-FBEDC9C7BA43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6E420B1-EE2F-4517-9952-FBEDC9C7BA43}.Release|Any CPU.Build.0 = Release|Any CPU
{68510D96-BECD-4B48-84B6-8D17975A74AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68510D96-BECD-4B48-84B6-8D17975A74AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68510D96-BECD-4B48-84B6-8D17975A74AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68510D96-BECD-4B48-84B6-8D17975A74AE}.Release|Any CPU.Build.0 = Release|Any CPU
{58DE0727-D9EB-4F96-95D8-54F275449649}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58DE0727-D9EB-4F96-95D8-54F275449649}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58DE0727-D9EB-4F96-95D8-54F275449649}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58DE0727-D9EB-4F96-95D8-54F275449649}.Release|Any CPU.Build.0 = Release|Any CPU
{A0279ACE-B0A8-43C9-86B8-D45B0A25BF24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0279ACE-B0A8-43C9-86B8-D45B0A25BF24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0279ACE-B0A8-43C9-86B8-D45B0A25BF24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0279ACE-B0A8-43C9-86B8-D45B0A25BF24}.Release|Any CPU.Build.0 = Release|Any CPU
{D0B92715-B833-4513-AE97-C20101437297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0B92715-B833-4513-AE97-C20101437297}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0B92715-B833-4513-AE97-C20101437297}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0B92715-B833-4513-AE97-C20101437297}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {68808FF0-79EA-4FFD-9EA2-4A1EE2B2893B}
EndGlobalSection
EndGlobal
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+90
View File
@@ -0,0 +1,90 @@
using System;
namespace Lesson
{
class Program
{
#region
//重载概念
//在同意语句块class或struct中
//函数(方法)名相同
//参数的数量不同
//或者
//函数的数量相同,但参数的类型或顺序不同
//作用:
//1.命名一组功能相似的函数,减少函数名的数量,避免命名空间的污染
//2.提升程序可读性
#endregion
#region
//注意:
//1.重载和返回值类型没有关系,之和参数类型,个数,顺序有关
//2.调用时 程序会自己根据传入的参数类型判断使用哪一个重载
//基础函数
static int CalcSum(int a, int b)
{
return a + b;
}
//类型相同 数量不同
static int CalcSum(int a, int b, int c)
{
return a + b + c;
}
//类型不同 数量相同
static float CalcSum(float a, float b)
{
return a + b;
}
//类型不同 数量不同
static float CalcSum(float a, int b)
{
return a + b;
}
//数量相同 顺序不同
static float CalcSum(int a, float b)
{
return a + b;
}
//只要不是完全相同,都可以重载
//ref和out也可以视为一种改变
static float CalcSum(ref int a, float b)
{
return a + b;
}
//params可变参数也可以视为一种改变
static float CalcSum(ref int a, float b, params int[] arr)
{
return a + b;
}
#endregion
static void Main(string[] args)
{
Console.WriteLine("基础函数:");
Console.WriteLine(CalcSum(1, 2));
Console.WriteLine("数量不同重载:");
Console.WriteLine(CalcSum(1, 2, 3));
Console.WriteLine("类型不同重载:");
Console.WriteLine(CalcSum(1.2f, 1.3f));
Console.WriteLine("类型数量都不同重载:");
Console.WriteLine(CalcSum(1.2f, 1));
Console.WriteLine("顺序不同重载:");
Console.WriteLine(CalcSum(1, 1.2f));
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,91 @@
using System;
namespace Lesson
{
class Program
{
static int Compare(int a, int b)
{
if (a > b)
{
return a;
}
else
{
return b;
}
}
static float Compare(float a, float b)
{
if (a > b)
{
return a;
}
else
{
return b;
}
}
static double Compare(double a, double b)
{
if (a > b)
{
return a;
}
else
{
return b;
}
}
static int CompareInf(params int[] a)
{
int max = 0;
for (int i = 0; i < a.Length; i++)
{
if (a[i] > max)
{
max = a[i];
}
}
return max;
}
static float CompareInf(params float[] a)
{
float max = 0.0f;
for (int i = 0; i < a.Length; i++)
{
if (a[i] > max)
{
max = a[i];
}
}
return max;
}
static double CompareInf(params double[] a)
{
double max = 0.0d;
for (int i = 0; i < a.Length; i++)
{
if (a[i] > max)
{
max = a[i];
}
}
return max;
}
static void Main(string[] args)
{
Console.WriteLine(Compare(1, 2));
Console.WriteLine(Compare(2.1f, 3.2f));
Console.WriteLine(Compare(3.675475d, 4.6435432d));
Console.WriteLine(CompareInf(1,2,3,4,5,6,7));
Console.WriteLine(CompareInf(1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f));
Console.WriteLine(CompareInf(1.1d, 1.2d, 1.3d, 1.4d, 1.5d, 1.6d, 1.7d));
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+45
View File
@@ -0,0 +1,45 @@
using System;
namespace Lesson
{
class Program
{
#region
//递归函数 就是 让函数自己调用自己
//static void Fun()
//{
// Fun();
//}
//注意:这样会爆内存
//所以 一个正确的递归函数必须要包括下面的特点
//1.必须有结束调用的条件
//2.用于条件判断的 这个条件 必须改变 能够达到停止的目的
#endregion
#region
//用递归函数打印出0到10
static void Print(int a = 0)
{
Console.WriteLine(a);
a++;
if (a <= 10)
{
Print(a);
}
else
{
return;
}
}
#endregion
static void Main(string[] args)
{
Print();
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,80 @@
using System;
namespace Lesson
{
class Program
{
#region
#endregion
#region
static int JieCheng(int max)
{
if (max == 0)
{
return 1;
}
else
{
return max * JieCheng(max - 1);
}
}
#endregion
#region
static int JieChengHe(int num)
{
if (num == 1)
{
return JieCheng(1);
}
return JieCheng(num) + JieChengHe(num-1);
}
#endregion
#region
static void Bamboo(float length, int day)
{
Console.WriteLine("长度为" + length);
length /= 2;
day--;
if (day < 0)
{
Console.WriteLine("长度为" + length);
return;
}
Bamboo(length, day);
}
#endregion
#region
static bool Fun(int num)
{
Console.WriteLine(num);
return num == 200 || Fun(num + 1);
}
#endregion
static void Main(string[] args)
{
Console.WriteLine(JieCheng(5));
Console.WriteLine(JieChengHe(10));
Bamboo(100,10);
Fun(0);
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+115
View File
@@ -0,0 +1,115 @@
using System;
namespace Lesson
{
#region
//结构体 是一种自定义变量类型 类似枚举需要自己定义
//他是数据和函数的集合
//在结构体中 可以声明各种变量和方法
//作用:用来表现存在关系的数据集合 比如用结构体变现学生 动物 人类等等
#endregion
#region
//1.结构体一般卸载 namespace语句块中
//2.结构体关键字 struct
//3.结构体中声明的变量不能直接初始化
struct StructName//可以是中文的
{
//第一部分
//变量(不能直接初始化
//第二部分
//构造函数(可选
//第三部分
//函数(一般情况下都有
}
//注意:结构体名字是帕斯卡命名法
#endregion
#region
struct Student
{
//变量
//年龄,性别,学号,姓名
#region 访
//修饰结构体中变量和方法 是否能够被外部使用
//public 公共的 可以被外部访问
//private 私有的 只能在内部使用
//默认不写 为private
#endregion
public int age;
public bool sex;
public int number;
public string name;
//结构体中可以包含其他结构体,但不能是本结构体
//构造函数
#region
//基本概念
//1.没有返回值
//2.函数名必须和结构体名相同
//3.必须有参数
//4.如果声明了构造函数 那么必须在其中队所有变量数据初始化
//5.结构体和构造函数可以重载,但是注意第4点
//构造函数一般用在外部,方便初始化使用的
public Student(int age, bool sex, int number, string name) //必须有参数
{
//新的关键字this,代表自己
this.age = age;//this.age是构造函数中写的age,而后面的age是结构体上面的声明的age
this.sex = sex;
this.number = number;
this.name = name;
}
#endregion
//函数
//表现这个数据结构的行为
//注意:在结构提中的方法,目前不需要加static关键字
public void Speak()
{
//在函数中可以直接使用结构体内部声明的变量
Console.WriteLine("我的名字是{0},今年{1}岁",name,age);
}
//函数可以根据需求写任意个
}
#endregion
class Program
{
static void Main(string[] args)
{
#region 使
//变量的声明
//变量类型 变量名;
Student s1;
//如果没写后private打s1.是tab不补齐的
s1.age = 18;
s1.sex = false;
s1.number = 123;
s1.name = "HKK";
s1.Speak();
Student s2 = new Student(8,true,321,"KKH");
//上面的代码可以替代下面的代码
//s2.age = 8;
//s2.sex = true;
//s2.number = 321;
//s2.name = "KKH";
s2.Speak();
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,179 @@
using System;
using System.Threading;
namespace Lesson
{
struct Member
{
public string name;
public bool sex;
public int age;
public string clas;
public string major;
public Member(string name, bool sex, int age, string clas, string major)
{
this.name = name;
this.sex = sex;
this.age = age;
this.clas = clas;
this.major = major;
}
public void PrintInfo()
{
Console.WriteLine("学员信息:");
Console.WriteLine($"姓名:{name}");
Console.WriteLine($"性别:{(sex ? "" : "")}"); // 将bool转换为中文
Console.WriteLine($"年龄:{age}");
Console.WriteLine($"班级:{clas}");
Console.WriteLine($"专业:{major}");
}
}
struct PlayerInfo
{
public string name;
public E_Occupation occupation;
public PlayerInfo(string name,E_Occupation occupation)
{
this.name = name;
this.occupation = occupation;
}
public void PrintInfo()
{
Console.WriteLine("玩家攻击信息");
switch (occupation)
{
case E_Occupation.Warrior:
Console.WriteLine($"{occupation}{name}释放了冲锋");
break;
case E_Occupation.Hunter:
Console.WriteLine($"{occupation}{name}释放了假死");
break;
case E_Occupation.Mage:
Console.WriteLine($"{occupation}{name}释放了奥数冲击");
break;
}
}
}
struct Monster
{
public string name;
public int atk;
public Monster(string name)
{
this.name = name;
Random r = new Random();
atk = r.Next(10,30);
}
public void Atk()
{
Console.WriteLine("{0}的攻击力为{1}",name,atk);
}
}
struct Atm
{
public string name;
public int atk;
public int def;
public int hp;
public Atm(string name,int atk,int def,int hp)
{
this.name = name;
this.atk = atk;
this.def = def;
this.hp = hp;
}
public void Atk(ref Boss monster)
{
monster.hp -= atk - monster.def;
Console.WriteLine("{0}攻击了{1}造成了{2}点伤害,{3}剩余{4}HP", name, monster.name, atk - monster.def,monster.name, monster.hp);
}
}
struct Boss
{
public string name;
public int atk;
public int def;
public int hp;
public Boss(string name, int atk, int def, int hp)
{
this.name = name;
this.atk = atk;
this.def = def;
this.hp = hp;
}
public void Atk(ref Atm atm)
{
atm.hp -= atk - atm.def;
Console.WriteLine("{0}攻击了{1}造成了{2}点伤害,{3}剩余{4}HP", name, atm.name, atk - atm.def,atm.name, atm.hp);
}
}
enum E_Occupation
{
/// <summary>
/// 战士
/// </summary>
Warrior,
/// <summary>
/// 猎人
/// </summary>
Hunter,
/// <summary>
/// 法师
/// </summary>
Mage
}
class Program
{
static void Main(string[] args)
{
Member m1 = new Member("123",true,18,"三年一班","计算机");
m1.PrintInfo();
Member m2 = new Member("321", false, 18, "一年三班", "算计机");
m2.PrintInfo();
PlayerInfo p1 = new PlayerInfo("HK", E_Occupation.Warrior);
p1.PrintInfo();
Monster[] monsters = new Monster[10];
for (int i = 0; i < monsters.Length; i++)
{
monsters[i] = new Monster("小怪兽"+i);
monsters[i].Atk();
}
Atm atm = new Atm("雷欧奥特曼",10,5,100);
Boss boss = new Boss("哥斯拉",8,4,100);
while (true)
{
atm.Atk(ref boss);
boss.Atk(ref atm);
if (boss.hp <= 0)
{
Console.WriteLine("你赢了");
break;
}
if (atm.hp <= 0)
{
Console.WriteLine("你输了");
break;
}
Console.WriteLine("按任意键继续");
Console.ReadKey(true);
}
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+69
View File
@@ -0,0 +1,69 @@
using System;
namespace Lesson
{
class Program
{
static void Print(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
#region
//排序是计算机内经常进行的一种操作,其目的是将一组“无序”的记录调整为“有序的”
int[] arr = new int[] { 8, 7, 1, 5, 4, 2, 6, 3, 9};
#endregion
Print(arr);
#region
//两两相比
//不停比较
//不停交换
#endregion
bool isSort;//声明一个标识来保存是否进行交换的状态
#region
int temp;
for (int i = 0; i < arr.Length; i++)
{
isSort = false;
for (int j = 0; j < arr.Length - 1 - i; j++)//-i可以直接省去后面已经确定位置那一轮的比较
{
if (arr[j] > arr[j + 1])
{
isSort = true;//被交换了被表示true
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
if (!isSort) { break; }//如果是true就继续交换,如果没有交换就false跳过这一轮
}
#endregion
Print(arr);
#region
//1.确定位置的数(极值)可以不用继续比了
//所以 没完成n轮 后面位置的数 就不用参与比较了
//2.特殊情况的优化
//比如在某一轮已经得到最终序列后,还会继续判断几轮,可以省去这几轮的时间
//
#endregion
#region
#endregion
#region
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,59 @@
using System;
namespace Lesson
{
class Program
{
static void Print(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
int[] arr = new int[20];
Random r = new Random();
for (int i = 0; i < arr.Length; i++)
{
arr[i] = r.Next(0,101);
}
Print(arr);
int temp;
bool isSort;
for (int i = 0; i < arr.Length; i++)
{
isSort = false;
for (int j = 0; j < arr.Length - 1 - i; j++)
{
if (arr[j] > arr[j + 1])
{
isSort = true;
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
if (!isSort) { break; }
}
Print(arr);
for (int i = 0; i < arr.Length; i++)
{
isSort = false;
for (int j = 0; j < arr.Length - 1 - i; j++)
{
if (arr[j] < arr[j + 1])
{
isSort = true;
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
if (!isSort) { break; }
}
Print(arr);
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+77
View File
@@ -0,0 +1,77 @@
using System;
namespace Lesson
{
class Program
{
static void Print(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
#region
//新建中间商
//依次比较
//找出极值(最大或最小
//放入目标位置
//比较n轮
#endregion
#region
//实现升序 把 大的 放在最后面
int[] arr = new int[] { 8, 7, 1, 5, 4, 2, 6, 3, 9 };
Print(arr);
////第一步 声明一个中间商 来记录索引
////每一轮开始 默认第一个都是极值
//int index = 0;
//第二步
//依次比较
//for (int n = 1; n < arr.Length; n++)
//{
// //第三步
// //找出极值(最大值)
// if (arr[index] < arr[n])
// {
// index = n;
// }
//}
////第四步 放入目标位置
////Length - 1 - 轮数
////如果当前极值所在位置 就是目标位置 那就没必要交换了
//if (index < arr.Length - 1 - 轮数)
//{
// int temp = arr[index];
// arr[index] = arr[arr.Length - 1 -轮数];
// arr[arr.Length - 1 - 轮数] = temp;
//}
//第五步 比较m轮
for (int m = 0; m < arr.Length; m++)
{
int index = 0;
for (int n = 1; n < arr.Length - m; n++)
{
if (arr[index] < arr[n])
{
index = n;
}
}
if (index < arr.Length - 1 - m)
{
int temp = arr[index];
arr[index] = arr[arr.Length - 1 - m];
arr[arr.Length - 1 - m] = temp;
}
}
Print(arr);
#endregion
}
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,64 @@
using System;
namespace Lesson
{
class Program
{
static void Print(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
int[] arr = new int[20];
Random r = new Random();
for (int i = 0;i < arr.Length; i++)
{
arr[i] = r.Next(1,101);
}
Print(arr);
for (int m = 0; m < arr.Length; m++)
{
int index = 0;
for (int n = 1; n < arr.Length - m; n++)
{
if (arr[index] < arr[n])
{
index = n;
}
}
if (index != arr.Length - 1 - m)
{
int temp = arr[index];
arr[index] = arr[arr.Length - 1 - m];
arr[arr.Length - 1 - m] = temp;
}
}
Print(arr);
for (int m = 0; m < arr.Length; m++)
{
int index = 0;
for (int n = 1; n < arr.Length - m; n++)
{
if (arr[index] > arr[n])
{
index = n;
}
}
if (index != arr.Length - 1 - m)
{
int temp = arr[index];
arr[index] = arr[arr.Length - 1 - m];
arr[arr.Length - 1 - m] = temp;
}
}
Print(arr);
}
}
}
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Lesson1__枚举练习</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+155
View File
@@ -0,0 +1,155 @@
using System;
namespace Lesson1_枚举练习
{
class Program
{
static void Main(string[] args)
{
#region
try
{
Console.WriteLine("选择你的状态:\n1.在线 2.离线 3.忙碌 4.离开");
int input1 = int.Parse(Console.ReadLine());
E_chatStatus chatStatus = (E_chatStatus)input1;
switch (chatStatus)
{
case E_chatStatus.online:
Console.WriteLine("你选择了在线状态");
break;
case E_chatStatus.offline:
Console.WriteLine("你选择了离线状态");
break;
case E_chatStatus.busy:
Console.WriteLine("你选择了忙碌状态");
break;
case E_chatStatus.away:
Console.WriteLine("你选择了离开状态");
break;
default:
Console.WriteLine("无效的状态");
break;
}
}
catch (Exception e)
{
Console.WriteLine("请输入正确的数字或名称");
Console.WriteLine("error code" + e);
throw;
}
#endregion
Console.WriteLine("press any key to continue");
int block = Console.ReadKey().KeyChar;
Console.Clear();
#region
try
{
Console.WriteLine("请你选择需要购买的咖啡:\n1.中杯medium 2.大杯large 3.特大杯extralarge");
string input2 = Console.ReadLine();
E_menu menu = (E_menu)Enum.Parse(typeof(E_menu), input2);
switch (menu)
{
case E_menu.medium:
Console.WriteLine("你选择了中杯咖啡,花费35");
break;
case E_menu.large:
Console.WriteLine("你选择了大杯咖啡,花费40");
break;
case E_menu.extralarge:
Console.WriteLine("你选择了特大杯咖啡,花费43");
break;
default:
Console.WriteLine("无效的选择");
break;
}
}
catch (Exception e)
{
Console.WriteLine("请输入正确的数字或名称");
Console.WriteLine("Error code:"+e);
throw;
}
#endregion
Console.WriteLine("press any key to continue");
block = Console.ReadKey().KeyChar;
Console.Clear();
#region
int Attack = 0, Defense = 0;
Console.WriteLine("请选择你的性别:\n1.男 2.女");
string input3 = Console.ReadLine();
E_sex sex = (E_sex)Enum.Parse(typeof(E_sex), input3);
Console.WriteLine("请你选择你的职业:\n1.战士 2.猎人 3.法师");
input3 = Console.ReadLine();
E_career career = (E_career)Enum.Parse(typeof(E_career), input3);
E_skill skill = E_skill.ArcaneBlast;
switch (sex)
{
case E_sex.male:
Attack += 50;
Defense += 100;
break;
case E_sex.female:
Attack += 150;
Defense += 20;
break;
default:
break;
}
switch (career)
{
case E_career.warrior:
Attack += 20;
Defense += 100;
skill = E_skill.Push;
break;
case E_career.hunter:
Attack += 120;
Defense += 30;
skill = E_skill.PlayDead;
break;
case E_career.mage:
Attack += 200;
Defense += 10;
skill = E_skill.ArcaneBlast;
break;
default:
break;
}
Console.WriteLine("You are "+sex+" "+career+"Attack"+Attack+"Defense"+Defense+"CareerSkill" + skill);
#endregion
}
}
enum E_chatStatus
{
online = 1,
offline = 2,
busy = 3,
away = 4
}
enum E_menu
{
medium = 1,
large = 2,
extralarge = 3
}
enum E_sex
{
male = 1,
female = 2
}
enum E_career
{
warrior = 1,
hunter = 2,
mage = 3
}
enum E_skill
{
Push = 1,
PlayDead = 2,
ArcaneBlast = 3
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+116
View File
@@ -0,0 +1,116 @@
using System;
#region
// 1.在namespace中声明枚举(常用)
// 2.在class中声明枚举
// 3.在struct中声明枚举
// 注意:枚举不能在函数,方法中声明
#endregion
namespace
{
#region
#region 1
//枚举是一个比较特别的存在
//他是一个被命名的整形常量的集合
//一般用它来表示 状态 类型 等等
#endregion
#region 2
//注意:声明枚举 和 声明枚举变量 是两回事
//声明枚举: 相当于是 闯将一个自定义的枚举类型
//声明枚举变量: 使用声明的自行定义枚举类型 创建一个枚举变量
#endregion
#region 3
// enum 枚举名
// 一般来说,枚举名以E或E_开头,作为一种默认的规范
//enum E_自定义枚举名
//{
// 自定义枚举项名字,// 这里是枚举中包裹的 整形常量 第一个默认值是0 下面会依次累加
// 自定义枚举项名字1,// 1
// 自定义枚举项名字2,// 2
//}
enum E_自定义枚举名
{
= 5,// 第一个默认值是5 下面会依次累加
1,// 这里会是6
2 = 100,// 改变默认值为100 下面还会依次累加
}
#endregion
#endregion
class Program
{
static void Main(string[] args)
{
#region 使
//例子-声明枚举变量
E_PlayerType playerType = E_PlayerType.Hunter;
if(playerType == E_PlayerType.Warlock)
{
Console.WriteLine("玩家是术士");
}
else if (playerType == E_PlayerType.Titan)
{
Console.WriteLine("玩家是泰坦");
}
else if (playerType == E_PlayerType.Hunter)
{
Console.WriteLine("玩家是猎人");
}
//枚举和switch非常配合
//甚至可以自动补全
E_MonsterType monsterType = E_MonsterType.Boss;
switch (monsterType)
{
case E_MonsterType.Normal:
Console.WriteLine("普通怪物的功能");
break;
case E_MonsterType.Boss:
Console.WriteLine("BOSS怪物的功能");
break;
default:
break;
}
#endregion
#region
//1.枚举和int互转
int i = (int)playerType;
Console.WriteLine(i);
//2.枚举和string互转
string str = playerType.ToString();
Console.WriteLine(str);
//3.字符串转枚举
//(括号强转写目标枚举类型)Enum.Parse(typeof(同样目标枚举类型), "完全一致的字符串");
playerType = (E_PlayerType)Enum.Parse(typeof(E_PlayerType), "Titan");
Console.WriteLine(playerType);
#endregion
#region
//在游戏开发中,对象很多的时候,会有很多状态
//比如玩家的动作状态,我们需要用变量或某种标识来表示玩家处于的是哪种状态
//如果用int来表示状态,数字的含义就不明确了
//如果用枚举来表示状态,枚举的名字就能清晰地表达出状态的含义
#endregion
}
}
#region -
enum E_MonsterType
{
Normal,
Boss,
}
enum E_PlayerType
{
Titan,
Warlock,
Hunter,
}
#endregion
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+130
View File
@@ -0,0 +1,130 @@
using System;
namespace Lesson2_一维数组
{
class Program
{
static void Main(string[] args)
{
#region
//数组是存储一组相同类型数据的集合
//数组分为 一维、多位、交错数组
//一般情况分为 一维数组 简称为数组
#endregion
#region
//数组的声明
// 变量类型[] 数组名; //只是声明了数组,没有分配内存空间
int[] arr1; //声明了一个整型数组变量arr1,但没有分配内存空间
// 变量类型[] 数组名 = new 变量类型[长度]; //声明并分配内存空间
int[] arr2 = new int[5]; //声明并分配了一个长度为5的整型数组arr2,
//此时数组中的每个元素都被初始化为默认值0
// 变量类型[] 数组名 = new 变量类型[长度] { 元素1, 元素2, ... }; //声明并初始化数组
int[] arr3 = new int[5] { 1, 2, 3, 4, 5 }; //声明并初始化了一个长度为5的整型数组arr3
// 变量类型[] 数组名 = new 变量类型[] { 元素1, 元素2, ... }; //声明并初始化数组,长度由元素个数决定
int[] arr4 = new int[] { 1, 2, 3, 4, 5 }; //声明并初始化了一个整型数组arr4,长度由元素个数决定
// 变量类型[] 数组名 = { 元素1, 元素2, ... }; //声明并初始化数组,长度由元素个数决定
int[] arr5 = { 1, 2, 3, 4, 5 }; //声明并初始化了一个整型数组arr5,长度由元素个数决定
#endregion
#region 使
int[] array = { 1, 2, 3, 4, 5 };
//1.数组的长度可以用变量.Length获取
Console.WriteLine(array.Length);
Console.ReadKey();
Console.Clear();
//2.数组的下标和索引是从0开始的
//注意:访问数组时,索引不能越界,范围在0到Length-1之间
Console.WriteLine(array[0]);//1
Console.WriteLine(array[4]);//5
Console.ReadKey();
Console.Clear();
//3.修改数组中的元素
array[0] = 10;
Console.WriteLine(array[0]);
Console.ReadKey();
Console.Clear();
//4.遍历数组
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
Console.ReadKey();
Console.Clear();
//5.增加数组的元素
//数组的长度是固定的,不能动态增加
//如果需要增加数组的元素,可以创建一个新的数组,将旧数组的元素复制到新数组中
int[] newArray = new int[array.Length + 1];
//迁移数组
for (int i = 0; i < array.Length; i++)
{
newArray[i] = array[i];
}
//给新数组的最后一个元素赋值
newArray[newArray.Length - 1] = 6;
//让array引用newArray
array = newArray;
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
Console.WriteLine("数组长度:" + array.Length);
Console.ReadKey();
Console.Clear();
//6.删除数组的元素
//数组的长度是固定的,不能动态删除
//如果需要删除数组的元素,可以创建一个新的数组,将旧数组的元素复制到新数组中
int[] newArray2 = new int[array.Length - 1];//这里假设删除的是最后一个元素,
//如果删除的是其他元素,需要调整索引
//迁移数组
for (int i = 0; i < newArray2.Length; i++)
{
newArray2[i] = array[i];
}
//让array引用newArray2
array = newArray2;
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
Console.WriteLine("数组长度:" + array.Length);
Console.ReadKey();
Console.Clear();
//7.查找数组中的元素
//可以使用循环遍历数组,查找指定元素
Console.WriteLine("请输入要查找的数");
int num = int.Parse(Console.ReadLine());//注意不能使用console.read
for (int i = 0; i < array.Length; i++)
{
if (array[i] == num)
{
Console.WriteLine($"找到了{num},索引为{i}");
break;
}
}
#endregion
}
}
}

Some files were not shown because too many files have changed in this diff Show More