Synchronization of old projects
Part1
This commit is contained in:
+175
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,199 @@
|
||||
#region 练习题一
|
||||
int[] array = new int[100];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] = i;
|
||||
Console.Write(array[i] + " ");
|
||||
}
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
|
||||
#region 练习题二
|
||||
int[] array2 = new int[100];
|
||||
for (int i = 0; i < array2.Length; i++)
|
||||
{
|
||||
array2[i] = array[i]*2;
|
||||
Console.Write(array2[i] + " ");
|
||||
}
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
|
||||
#region 练习题三
|
||||
int[] array3 = new int[100];
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < array3.Length; i++)
|
||||
{
|
||||
array3[i] = r.Next(0,101);
|
||||
Console.Write(array3[i] + " ");
|
||||
}
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
|
||||
#region 练习题四
|
||||
int[] array4 = new int[100];
|
||||
int max=0, min=100, sum=0, avg=0;
|
||||
for (int i = 0; i < array4.Length; i++)
|
||||
{
|
||||
array4[i] = r.Next(0, 101);
|
||||
if(max < array4[i])
|
||||
{
|
||||
max = array4[i];
|
||||
}
|
||||
if(min > array4[i])
|
||||
{
|
||||
min = array4[i];
|
||||
}
|
||||
sum += array4[i];
|
||||
avg = sum / array4.Length;
|
||||
Console.Write(array4[i] + " ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"最大值为:{max}");
|
||||
Console.WriteLine($"最小值为:{min}");
|
||||
Console.WriteLine($"总和为:{sum}");
|
||||
Console.WriteLine($"平均值为:{avg}");
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
|
||||
#region 练习题五
|
||||
int[] array5 = new int[10];
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
array5[i] = r.Next(0, 101);
|
||||
Console.Write(array5[i] + " ");
|
||||
}
|
||||
//反转
|
||||
int temp;
|
||||
for (int i = 0; i < array5.Length / 2; i++)
|
||||
{
|
||||
temp = array5[i];
|
||||
array5[i] = array5[array5.Length - 1 - i];
|
||||
array5[array5.Length - 1 - i] = temp;
|
||||
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("反转后:");
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
Console.Write(array5[i] + " ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("反打反转:");
|
||||
for (int i = array5.Length - 1; i >= 0; i--)
|
||||
{
|
||||
Console.Write(array5[i] + " ");
|
||||
}
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
|
||||
#region 练习题六
|
||||
int[] array6 = new int[10];
|
||||
for (int i = 0; i < array6.Length; i++)
|
||||
{
|
||||
array6[i] = r.Next(-10, 11);
|
||||
Console.Write(array6[i] + " ");
|
||||
}
|
||||
for (int i = 0;i < array6.Length; i++)
|
||||
{
|
||||
if (array6[i] < 0)
|
||||
{
|
||||
array6[i] -= 1;
|
||||
}
|
||||
else if (array6[i] > 0)
|
||||
{
|
||||
array6[i] += 1;
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("处理后:");
|
||||
for (int i = 0; i < array6.Length; i++)
|
||||
{
|
||||
Console.Write(array6[i] + " ");
|
||||
}
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
|
||||
#region 练习题七
|
||||
int[] array7 = new int[10];
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < array7.Length; i++)
|
||||
{
|
||||
Console.Write($"请输入第{i + 1}位同学的成绩:");
|
||||
array7[i] = int.Parse(Console.ReadLine());
|
||||
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("输入错误,请输入数字!");
|
||||
return;
|
||||
}
|
||||
max = array7[0];
|
||||
min = array7[0];
|
||||
sum = 0;
|
||||
avg = 0;
|
||||
for (int i = 0; i < array7.Length; i++)
|
||||
{
|
||||
if (max < array7[i])
|
||||
{
|
||||
max = array7[i];
|
||||
}
|
||||
if (min > array7[i])
|
||||
{
|
||||
min = array7[i];
|
||||
}
|
||||
sum += array7[i];
|
||||
}
|
||||
avg = sum / array7.Length;
|
||||
Console.WriteLine($"成绩最高成绩为{max}");
|
||||
Console.WriteLine($"成绩最低成绩为{min}");
|
||||
Console.WriteLine($"成绩总和成绩为{sum}");
|
||||
Console.WriteLine($"平均成绩成绩为{avg}");
|
||||
for (int i = 0; i < array7.Length; i++)
|
||||
{
|
||||
if (array7[i] >= 60)
|
||||
{
|
||||
Console.WriteLine($"第{i + 1}位同学成绩为:{array7[i]},成绩合格");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"第{i + 1}位同学成绩为:{array7[i]},成绩不合格");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 练习题八
|
||||
string[] array8 = new string[25];
|
||||
for (int i = 0; i < array8.Length; i++)
|
||||
{
|
||||
//if (i % 2 == 0)
|
||||
//{
|
||||
// array8[i] = "■";
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// array8[i] = "□";
|
||||
//}
|
||||
array8[i] = i % 2 == 0 ? "■" : "□";//无敌
|
||||
//打印
|
||||
Console.Write(array8[i]);
|
||||
if ((i + 1) % 5 == 0)
|
||||
{
|
||||
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,171 @@
|
||||
#region 知识点一 基本概念
|
||||
//二维数组 是使用两个索引来引用的数组。
|
||||
//它可以看作是一个表格,有行和列。
|
||||
//可以用来表示矩阵、棋盘等二维数据结构。
|
||||
//
|
||||
#endregion
|
||||
|
||||
#region 知识点二 声明和初始化
|
||||
//1.变量类型[,] 变量名;
|
||||
int[,] arr1;//声明后必须初始化
|
||||
|
||||
//2.变量类型[,] 变量名 = new 变量类型[行数, 列数];
|
||||
int[,] arr2 = new int[2, 3];//声明并初始化,默认值为0
|
||||
//二维数组的行数和列数必须是常量表达式,不能是变量。
|
||||
|
||||
//3.变量类型[,] 变量名 = { {元素1, 元素2}, {元素3, 元素4} };
|
||||
int[,] arr3 = { { 1, 2 }, { 3, 4 } };//声明并初始化
|
||||
|
||||
//4.变量类型[,] 变量名 = new 变量类型[行数, 列数] { {元素1, 元素2}, {元素3, 元素4} };
|
||||
int[,] arr4 = new int[2, 2] { { 1, 2 },
|
||||
{ 3, 4 } };//声明并初始化
|
||||
|
||||
//5.变量类型[,] 变量名 = new 变量类型[,] { {元素1, 元素2}, {元素3, 元素4} };
|
||||
int[,] arr5 = new int[,] { { 1, 2 },
|
||||
{ 3, 4 } };//声明并初始化
|
||||
|
||||
#endregion
|
||||
|
||||
#region 知识点三 二维数组的使用
|
||||
//1.二维数组的长度
|
||||
Console.WriteLine("二维数组的长度");
|
||||
int[,] array = new int[,] { { 1, 2, 3 },
|
||||
{ 4, 5, 6 } };
|
||||
//二维数组的长度可以分为行数,列数和总元素个数
|
||||
//获取二维数组的第0维长度(行数)
|
||||
Console.WriteLine(array.GetLength(0));
|
||||
//获取二维数组的第1维长度(列数)
|
||||
Console.WriteLine(array.GetLength(1));
|
||||
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
//2.获取二维数组中的元素
|
||||
Console.WriteLine("获取二维数组中的元素");
|
||||
//注意:第一个元素是0行0列,最后一个元素是(行数-1)列(列数-1)
|
||||
Console.WriteLine(array[0, 0]);//1
|
||||
Console.WriteLine(array[1, 2]);//6
|
||||
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
//3.修改二维数组中的元素
|
||||
Console.WriteLine("修改二维数组中的元素");
|
||||
array[0, 0] = 10;
|
||||
Console.WriteLine(array[0, 0]);//10
|
||||
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
//4.遍历二维数组
|
||||
Console.WriteLine("遍历二维数组");
|
||||
for (int i =0; i < array.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < array.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(array[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
//5.增加数组的元素
|
||||
Console.WriteLine("增加数组的元素");
|
||||
//二维数组的大小是固定的,不能动态增加元素。
|
||||
//如果需要增加元素,可以创建一个新的二维数组,并将原数组的元素复制到新数组中。
|
||||
int newRow = array.GetLength(0) + 1;
|
||||
int newCol = array.GetLength(1);
|
||||
int[,] newArray = new int[newRow, newCol];
|
||||
|
||||
for (int i = 0; i < array.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < array.GetLength(1); j++)
|
||||
{
|
||||
newArray[i, j] = array[i, j];
|
||||
}
|
||||
}
|
||||
array = newArray;
|
||||
array[2, 0] = 7;
|
||||
array[2, 1] = 8;
|
||||
array[2, 2] = 9;
|
||||
for (int i = 0; i < array.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < array.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(array[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
//6.删除数组的元素
|
||||
Console.WriteLine("删除数组的元素");
|
||||
//二维数组的大小是固定的,不能动态删除元素。
|
||||
//如果需要删除元素,可以创建一个新的二维数组,并将原数组的元素复制到新数组中,跳过要删除的元素。
|
||||
newRow = array.GetLength(0)-1;
|
||||
newCol = array.GetLength(1);
|
||||
newArray = new int[newRow, newCol];
|
||||
Console.WriteLine($"原数组行数{array.GetLength(0)}\t原数组列数{array.GetLength(1)}");
|
||||
Console.WriteLine($"新组行数{newArray.GetLength(0)}\t新组列数{newArray.GetLength(1)}");
|
||||
Console.WriteLine("打印原数组:");
|
||||
for (int i = 0; i < array.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < array.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(array[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
//假设删除第2行
|
||||
for (int i = 0; i < newArray.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < newArray.GetLength(1); j++)
|
||||
{
|
||||
newArray[i, j] = array[i, j];
|
||||
}
|
||||
}
|
||||
array = newArray;//引用新数组
|
||||
Console.WriteLine("打印新数组:");
|
||||
for (int i = 0; i < array.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < array.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(array[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
|
||||
//7.查找数组中的元素
|
||||
Console.WriteLine("查找数组中的元素");
|
||||
//如果要在数组中查找某个元素,可以使用循环遍历数组,逐个比较元素值。
|
||||
//找到后可以记录下标或者直接返回元素。
|
||||
for (int i = 0; i < array.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < array.GetLength(1); j++)
|
||||
{
|
||||
if (array[i, j] == 5)
|
||||
{
|
||||
Console.WriteLine($"找到了元素5,位置在:{i}行{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>
|
||||
@@ -0,0 +1,180 @@
|
||||
#region 练习题一
|
||||
int[,] arr1 = new int[100, 100];
|
||||
int index = 1;
|
||||
for (int i = 0; i < arr1.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr1.GetLength(1); j++)
|
||||
{
|
||||
arr1[i, j] = index;
|
||||
++index;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr1.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr1.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr1[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题二
|
||||
Console.WriteLine("练习题二");
|
||||
int[,] arr2 = new int[6, 6];
|
||||
Random r = new Random();
|
||||
Console.WriteLine(arr2.GetLength(0) / 2 + " " + arr2.GetLength(1) / 2);
|
||||
for (int i = 0; i < arr2.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr2.GetLength(1); j++)
|
||||
{
|
||||
if (i < arr2.GetLength(0)/2 && j+1 > arr2.GetLength(1)/2)
|
||||
arr2[i, j] = 0;
|
||||
else
|
||||
arr2[i, j] = r.Next(1, 11);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr2.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr2.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr2[i, j] + "\t");//+" "+ i + j +
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题三
|
||||
Console.WriteLine("练习题三");
|
||||
int[,] arr3 = new int[3, 3];
|
||||
int sum = 0;
|
||||
for (int i = 0; i < arr3.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr3.GetLength(1); j++)
|
||||
{
|
||||
arr3[i, j] = r.Next(1,11);
|
||||
if (i == j)
|
||||
sum += arr3[i, j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr3.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr3.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr3[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine(sum);
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题四
|
||||
Console.WriteLine("练习题四");
|
||||
int[,] arr4 = new int[3, 3];
|
||||
sum = 0;
|
||||
for (int i = 0; i < arr4.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr4.GetLength(1); j++)
|
||||
{
|
||||
arr4[i, j] = r.Next(1, 11);
|
||||
if (i == j)
|
||||
sum += arr4[i, j];
|
||||
else if (i + j == arr4.GetLength(1) - 1)
|
||||
sum += arr4[i, j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr4.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr4.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr4[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine(sum);
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题五
|
||||
Console.WriteLine("练习题五");
|
||||
int[,] arr5 = new int[5, 5];
|
||||
int max = 0;
|
||||
int min = 11;
|
||||
for (int i = 0; i < arr5.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr5.GetLength(1); j++)
|
||||
{
|
||||
arr5[i, j] = r.Next(1,11);
|
||||
if (arr5[i, j] > max)
|
||||
max = arr5[i, j];
|
||||
if (arr5[i, j] < min)
|
||||
min = arr5[i, j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr5.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr5.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr5[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine(max);
|
||||
Console.WriteLine(min);
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题六
|
||||
Console.WriteLine("练习题六");
|
||||
int m = 5, n = 5;
|
||||
int[,] arr6 = new int[m, n];
|
||||
//bool类型的数组默认值是false,所以可以用来标记某个位置是否被访问过
|
||||
bool[] hang = new bool[m];
|
||||
bool[] lie = new bool[n];
|
||||
for (int i = 0; i < arr6.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr6.GetLength(1); j++)
|
||||
{
|
||||
arr6[i, j] = r.Next(0, 2);
|
||||
Console.Write(arr6[i, j] + "\t");
|
||||
if (arr6[i, j] == 1)
|
||||
{
|
||||
hang[i] = true;
|
||||
lie[j] = true;
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine("分割");
|
||||
for (int i = 0; i < arr6.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr6.GetLength(1); j++)
|
||||
{
|
||||
if (hang[i] == true || lie[j] == true)
|
||||
{
|
||||
arr6[i, j] = 1;
|
||||
}
|
||||
Console.Write(arr6[i, j] + "\t");
|
||||
}
|
||||
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,58 @@
|
||||
#region 知识点一 基本概念
|
||||
//交错数组 是 数组的数组,每个维度的数量可以不同
|
||||
//注意:二维数组的每行的列数相同,交错数组每行的列数可能不同
|
||||
//一般情况下都用于行列数不一的情况
|
||||
#endregion
|
||||
|
||||
#region 知识点二 数组的声明
|
||||
//1.变量类型[][] 交错数组名;
|
||||
int[][] arr1;
|
||||
|
||||
//2.变量类型[][] 交错数组名 = new 变量类型[行数][];
|
||||
int[][] arr2 = new int[3][];
|
||||
|
||||
//3.变量类型[][] 交错数组名 = new 变量类型[行数][]{一维数组,一维数组2,......};
|
||||
int[][] arr3 = new int[3][] { new int[] {1,2,3 },
|
||||
new int[] {1,2},
|
||||
new int[] {1,2,3 }
|
||||
};
|
||||
//4.变量类型[][] 交错数组名 = new 变量类型[][]{一维数组,一维数组2,......};
|
||||
int[][] arr4 = new int[][] { new int[] {1,2,3 },
|
||||
new int[] {1,2},
|
||||
new int[] {1,2,3 }
|
||||
};
|
||||
//5.变量类型[][] 交错数组名 = {一维数组,一维数组2,......};
|
||||
int[][] arr5 = { new int[] {1,2,3 },
|
||||
new int[] {1,2},
|
||||
new int[] {1,2,3 }
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region 知识点三 数组的使用
|
||||
int[][] array = { new int[] { 1,2,3},
|
||||
new int[] {4,5}
|
||||
};
|
||||
//1.数组长度
|
||||
//行
|
||||
Console.WriteLine(array.GetLength(0));
|
||||
//列(得到某一行的列数
|
||||
Console.WriteLine(array[0].Length);
|
||||
|
||||
//2.获取交错数组中的元素(注意别越界
|
||||
Console.WriteLine(array[0][1]);
|
||||
|
||||
//3.修改元素(同上
|
||||
array[0][1] = 99;
|
||||
|
||||
//4.遍历
|
||||
for (int i = 0; i < array.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < array[i].Length; j++)
|
||||
{
|
||||
Console.Write(array[i][j]+"\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
//5.增删查(懒得写)
|
||||
#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,63 @@
|
||||
#region 知识点一 变量类型的复习
|
||||
//无符号整形
|
||||
//byte b = 1;
|
||||
//ushort us = 1;
|
||||
//uint ui = 1;
|
||||
//ulong ul = 1;
|
||||
|
||||
//有符号整形
|
||||
//sbyte sb = -1;
|
||||
//short s = -1;
|
||||
//int i = -1;
|
||||
//long l = -1;
|
||||
|
||||
//浮点型
|
||||
//float f = 1f;
|
||||
//double d = 1.1;
|
||||
//decimal dec = 1.1m;
|
||||
|
||||
//特殊类型
|
||||
//bool bo = true;
|
||||
//char c = 'a';
|
||||
//string str = "string";
|
||||
|
||||
//复杂类型
|
||||
//enum 枚举
|
||||
//数组(一维、二维、交错)
|
||||
|
||||
//把以上 学过的变量类型 分成 值类型和引用类型
|
||||
//引用类型:string,数组,类(未学习)
|
||||
//值类型:其他、结构体(未学习)
|
||||
#endregion
|
||||
|
||||
#region 知识点二 值类型和引用类型的区别
|
||||
//1.使用上的区别
|
||||
//值类型
|
||||
int a = 10;
|
||||
//引用类型
|
||||
int[] arr = new int[] { 1, 2, 3, 4 };
|
||||
|
||||
|
||||
//声明了一个b让其等于之前的a
|
||||
int b = a;
|
||||
//声明了一个arr2让其等于之前的arr
|
||||
int[] arr2 = arr;
|
||||
Console.WriteLine("a={0},b={1}",a,b);
|
||||
Console.WriteLine("arr[0]={0},arr2[0]={1}", arr[0], arr2[0]);
|
||||
|
||||
b = 20;
|
||||
arr2[0] = 5;
|
||||
Console.WriteLine("修改了b和arr2[0]后:");
|
||||
Console.WriteLine("a={0},b={1}", a, b);
|
||||
Console.WriteLine("arr[0]={0},arr2[0]={1}", arr[0], arr2[0]);
|
||||
|
||||
//值类型 在相互赋值时,是将值进行复制,互不影响,他变我不变
|
||||
|
||||
//引用类型 在相互赋值时,是将地址进行复制,互相关联,他变我也变
|
||||
|
||||
//2.为什么有以上区别
|
||||
//值类型和应用类型 存储在的内存区域是不同的 存储方式是不同的
|
||||
//值类型 直接存储在 栈内存 中 -- 系统分配,自动回收,小而快
|
||||
//引用类型 变量本身存储在 栈内存 中,实际数据存储在 堆内存 中 -- 手动分配,手动回收,大而慢
|
||||
//string虽然也是引用类型 但它有值类型的特性,因为它不可变
|
||||
#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 @@
|
||||
#region 知识点一 复习值和引用类型
|
||||
// 值类型-他变我不变,存储在栈内存中
|
||||
// 无符号整形,有符号整形,浮点数,char,bool,结构体,enum
|
||||
|
||||
// 引用类型-他变我也变,存储在堆内存中
|
||||
// string,数组,类
|
||||
#endregion
|
||||
|
||||
#region 知识点二 string类型的特殊性
|
||||
string str1 = "123";
|
||||
string str2 = str1;
|
||||
//因为string是引用类型,所以str2和str1应该是指向同一个地址的
|
||||
str2 = "321";
|
||||
Console.WriteLine(str1);
|
||||
Console.WriteLine(str2);
|
||||
//但是输出结果是str1=123,str2=321
|
||||
//原因:string类型是不可变类型
|
||||
//修改,或重新给string类型赋值时,重新开辟了一块堆内存空间来存储新的值
|
||||
//当str2重新指回"123"时,str2和str1才会指向同一个地址
|
||||
//但是堆内存中原来存储"321"没被引用,就变成了垃圾,等待垃圾回收器来回收
|
||||
|
||||
//所以string会有优化替代的方案(后面教)
|
||||
#endregion
|
||||
|
||||
#region 补充知识点 断点调试
|
||||
//通过断点调试 在监视窗口中查看内存信息
|
||||
//断点:窗口最左侧红点
|
||||
//调试->窗口->监视
|
||||
//F10逐步执行
|
||||
string str4 = "123";
|
||||
string str5 = str1;
|
||||
str5 = "321";
|
||||
Console.WriteLine(str4);
|
||||
Console.WriteLine(str5);
|
||||
#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,138 @@
|
||||
using System;
|
||||
namespace Lesson7_函数
|
||||
{
|
||||
class Program
|
||||
{
|
||||
#region 知识点一 基本概念
|
||||
//函数(方法)
|
||||
//本质是一块具有名称的代码块
|
||||
//可以使用函数(方法)的名称来调用它
|
||||
//函数(方法)是封装代码进行重复使用的手段
|
||||
|
||||
//函数(方法)的主要作用
|
||||
//1.封装代码
|
||||
//2.提高代码的复用性
|
||||
//3.抽象行为
|
||||
#endregion
|
||||
|
||||
#region 知识点二 函数写在哪里
|
||||
//1.class类里面
|
||||
//2.struct结构体里面
|
||||
#endregion
|
||||
|
||||
#region 知识点三 基本语法
|
||||
//4个部分
|
||||
// 1 2 3 4
|
||||
// static 返回类型 函数名(参数类型 参数名1,参数类型 参数名2.......)
|
||||
// {
|
||||
// 函数体(代码)
|
||||
// 5(可选,根据返回类型)
|
||||
// return 返回值;
|
||||
// }
|
||||
|
||||
//1 static
|
||||
//不是必须的 在没有学习类和结构体之前 先统一写上
|
||||
//2.1 返回类型
|
||||
//void 表示没有返回值
|
||||
//返回类型可以是任何数据类型 14种变量类型+复杂数据类型(数组、枚举、结构体)
|
||||
//3 函数名
|
||||
//使用帕斯卡命名法(PascalCase) 每个单词首字母大写
|
||||
//4.1 参数列表
|
||||
//不是必须的,可以没有参数 多个参数时,使用逗号间隔 参数类型也可以是任何数据类型
|
||||
//4.2 参数的命名
|
||||
//使用驼峰命名法(camelCase) 第一个单词首字
|
||||
//5 return
|
||||
//当返回类型不是void时 必须使用return语句 来返回一个与返回类型匹配的值
|
||||
//void也可以使用return 但不能返回任何值 只能单独使用return来结束函数
|
||||
#endregion
|
||||
|
||||
#region 知识点四 实际运用
|
||||
//1.无参无返回值
|
||||
static void SayHello()
|
||||
{
|
||||
Console.WriteLine("Hello World");
|
||||
//return; //可选
|
||||
}
|
||||
|
||||
//2.有参无返回值
|
||||
static void SayYourName(string name)
|
||||
{
|
||||
Console.WriteLine("Hello " + name);
|
||||
}
|
||||
//3.无参有返回值
|
||||
static string WhatsYourName()
|
||||
{
|
||||
return "王五";
|
||||
}
|
||||
//4.有参有返回值
|
||||
static int Sum(int a,int b)
|
||||
{
|
||||
return a + b;//return后面可以是一个表达式
|
||||
}
|
||||
//5.有参有返回值(多个参数)
|
||||
//函数的返回值只能有一个,多个返回值时,可以使用数组、结构体、类等复杂数据类型来实现
|
||||
static float[] AverageAndSum(int a, int b)
|
||||
{
|
||||
int sum = a + b;
|
||||
float avg = (a + b) / 2.0f;
|
||||
return new float[] { sum, avg};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 知识点五 关于return
|
||||
//即使函数没有返回值,也可以使用return
|
||||
//return可以直接不执行return后的代码,直接结束函数
|
||||
static void Speek(string str)
|
||||
{
|
||||
if (str == "脏话")
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//调用函数
|
||||
//函数名(参数);
|
||||
SayHello();
|
||||
Console.WriteLine();
|
||||
|
||||
//传入一个string类型的参数
|
||||
string str = "张三";
|
||||
SayYourName(str);
|
||||
//直接传入一个string类型的值
|
||||
SayYourName("李四");
|
||||
Console.WriteLine();
|
||||
|
||||
//接收WhatsYourName的返回值并传入SayYourName
|
||||
SayYourName(WhatsYourName());
|
||||
Console.WriteLine();
|
||||
|
||||
//一般来说
|
||||
//有返回值的函数 直接拿返回值使用 或 拿变量接收返回值
|
||||
string str2 = WhatsYourName();
|
||||
|
||||
//也可以直接调用,但没有任何意义
|
||||
WhatsYourName();
|
||||
|
||||
//传入两个int类型的参数 让Sum函数运算 并接打印返回值
|
||||
Console.WriteLine(Sum(10, 20));
|
||||
Console.WriteLine();
|
||||
|
||||
float[] arr = AverageAndSum(5, 7);
|
||||
Console.WriteLine("sum" + arr[0] + "\t" + "avg" + arr[1]);
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("return:");
|
||||
Speek("脏话");//不会返回脏话
|
||||
Console.WriteLine("不return");
|
||||
Speek("好话");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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,85 @@
|
||||
using System;
|
||||
namespace Lesson7
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Compare(int a, int b)
|
||||
{
|
||||
int max = (a > b) ? a : b;
|
||||
return max;
|
||||
}
|
||||
|
||||
static float[] Circle(float r)
|
||||
{
|
||||
float pi = 3.14f;
|
||||
float perimeter = 2 * pi * r;
|
||||
float area = pi * (r * r);
|
||||
return new float[] { perimeter, area };
|
||||
}
|
||||
static int[] ComplexCompare(int[] a)
|
||||
{
|
||||
int sum = 0, min = a[0],max = a[0],avg=0;
|
||||
for (int i = 0; i < a.Length; i++)
|
||||
{
|
||||
sum += a[i];
|
||||
if (a[i] > max)
|
||||
{
|
||||
max = a[i];
|
||||
}
|
||||
if (a[i] < min)
|
||||
{
|
||||
min = a[i];
|
||||
}
|
||||
}
|
||||
avg = sum / a.Length;
|
||||
return new int[] { sum, max, min, avg };
|
||||
}
|
||||
static bool Primenumber(int a)
|
||||
{
|
||||
for (int i = 2; i < a; i++)
|
||||
{
|
||||
if (a % i == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static bool Year(int a)
|
||||
{
|
||||
if (a%400 == 0 || (a%4 == 0 && a%100 != 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static void Main(string[] arg)
|
||||
{
|
||||
Console.WriteLine("比较大小:");
|
||||
Console.WriteLine(Compare(10, 20));
|
||||
|
||||
Console.WriteLine("圆:");
|
||||
float[] circle = Circle(20);
|
||||
Console.WriteLine("perimeter:" + circle[0] + " " + "area:" + circle[1]);
|
||||
|
||||
Console.WriteLine("综合:");
|
||||
int[] x = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
int[] result = ComplexCompare(x);
|
||||
Console.WriteLine("总和:" + result[0] + "最大" + result[1] + "最小" + result[2] + "平均" + result[3]);
|
||||
|
||||
bool result2 = Primenumber(21);
|
||||
if (result2)
|
||||
{
|
||||
Console.WriteLine("是质数");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("不是质数");
|
||||
}
|
||||
|
||||
Console.WriteLine("闰年:");
|
||||
Console.WriteLine(Year(2200));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,144 @@
|
||||
using System;
|
||||
namespace Lesson
|
||||
{
|
||||
class Program
|
||||
{
|
||||
#region 知识点一 学习ref和out的原因
|
||||
//他们可以解决 在函数内部改变外部传入的内容 里面变了 外面也要变
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region 知识点二 ref和out的使用
|
||||
//函数参数的修饰符
|
||||
//当传入的值类型参数在内部修改 或引用类型参数在内部重新声明时
|
||||
//外部的值会发生变化
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region 知识点三 ref和out的区别
|
||||
//1.ref传入的变量必须在外部初始化,out不用
|
||||
//2.out传入的变量必须在内部赋值,ref不用
|
||||
|
||||
//1
|
||||
//int a;
|
||||
//ChangeValueRef(ref a);//报错
|
||||
//ChangeValueOut(out a);//不报错
|
||||
|
||||
//2
|
||||
// static void ChangeValueOut(out int value)
|
||||
// {
|
||||
// value = 99;//不赋值报错
|
||||
// }
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//ref(在函数类型参数前用ref修饰
|
||||
static void ChangeValueRef(ref int value)
|
||||
{
|
||||
value = 99;
|
||||
}
|
||||
static void ChangeArrayRef(ref int[] arr)
|
||||
{
|
||||
arr = new int[] { 99, 99, 99 };
|
||||
}
|
||||
//out(在函数类型参数前用out修饰
|
||||
static void ChangeValueOut(out int value)
|
||||
{
|
||||
value = 99;
|
||||
}
|
||||
static void ChangeArrayOut(out int[] arr)
|
||||
{
|
||||
arr = new int[] { 99, 99, 99 };
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void ChangeValue(int value)
|
||||
{
|
||||
value = 99;
|
||||
}
|
||||
static void ChangeArrayValue(int[] arr)
|
||||
{
|
||||
arr[0] = 99;//将arr2的地址传给arr,两个地址指向的地址都一样,再将地址上的值从1改为99
|
||||
}
|
||||
|
||||
static void ChangeArrayValue2(int[] arr)
|
||||
{
|
||||
arr = new int[] { 99 };//将arr2的地址传给arr,两个地址指向的地址都一样,
|
||||
//在新开一个arr数组,但此时arr和arr2的联系断了,
|
||||
//arr新开了一个地址来存放99,arr2还是1
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("尝试直接使用函数修改a的值到99:");
|
||||
//试图使用函数修改a的值
|
||||
int a = 1;
|
||||
ChangeValue(a);
|
||||
Console.WriteLine(a);//外部值不变
|
||||
//在值类型和引用类型中有讲到,这是值类型,新开内存,拷贝值
|
||||
|
||||
Console.WriteLine("尝试直接使用函数修改arr2[0]的值到99:");
|
||||
int[] arr2 = { 1, 2, 3 };//复原
|
||||
ChangeArrayValue(arr2);
|
||||
Console.WriteLine(arr2[0]);//内外同值99
|
||||
//在值类型和引用类型中有讲到,这是引用类型,不新开,直接拷贝地址,arr2和函数的arr指向同一地址
|
||||
|
||||
Console.WriteLine("尝试直接使用函数修改arr2[0]的值到99:(但在函数中new了一个数组)");
|
||||
arr2 = new int[] { 1, 2, 3 };//复原
|
||||
ChangeArrayValue2(arr2);
|
||||
Console.WriteLine(arr2[0]);//外部值不变
|
||||
//引用类型,但是在函数内新开了内存,arr2和arr指向的不是同一地址,只修改了函数内部arr[0]的值
|
||||
|
||||
|
||||
//如果在函数中new了一个数组,那么怎么保持内外部统一一个值呢
|
||||
//ref和out就是来解决这个问题的
|
||||
//用ref来改变值类型的值
|
||||
Console.WriteLine("使用ref函数修改a的值到99:");
|
||||
a = 1;//复原
|
||||
ChangeValueRef(ref a);//需要在传入参数时也加上ref修饰符
|
||||
Console.WriteLine(a);//内外同值99
|
||||
|
||||
//用ref来改变引用类型的值
|
||||
arr2 = new int[] { 1,2,3 };//复原
|
||||
Console.WriteLine("使用ref函数修改arr2[]的值到99:(在函数中new了一个数组)");
|
||||
ChangeArrayRef(ref arr2);
|
||||
Console.WriteLine(arr2[0]);//内外同值99
|
||||
|
||||
//用out来改变值类型的值
|
||||
Console.WriteLine("使用out函数修改a的值到99:");
|
||||
a = 1;//复原
|
||||
ChangeValueOut(out a);
|
||||
Console.WriteLine(a);
|
||||
|
||||
//用out来改变引用类型的值
|
||||
Console.WriteLine("使用out函数修改arr2[]的值到99:(在函数中new了一个数组)");
|
||||
arr2 = new int[] { 1, 2, 3};
|
||||
ChangeArrayOut(out arr2);
|
||||
Console.WriteLine(arr2[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>
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
namespace Lesson
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static bool Login(string name, string password, ref string info )
|
||||
{
|
||||
string rightUserName = "admin";
|
||||
string rightPassword = "admin123";
|
||||
if (name == rightUserName && password == rightPassword)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (name == rightUserName && password != rightPassword )
|
||||
{
|
||||
info = "密码错误";
|
||||
return false;
|
||||
}
|
||||
else if (name != rightUserName && password == rightPassword)
|
||||
{
|
||||
info = "账号错误";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
info = "全错全错!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string inputUserName, inputPassword;
|
||||
Console.Write("请输入用户名:");
|
||||
inputUserName = Console.ReadLine();
|
||||
Console.Write("请输入密码:");
|
||||
inputPassword = Console.ReadLine();
|
||||
string info = "";
|
||||
bool access = Login(inputUserName,inputPassword,ref info);
|
||||
if (access)
|
||||
{
|
||||
Console.WriteLine("登录成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("登录失败"+ '\n' + info);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,69 @@
|
||||
using System;
|
||||
namespace Lesson
|
||||
{
|
||||
class Program
|
||||
{
|
||||
#region 知识点一 函数语法复习
|
||||
//1.静态关键词 可选,目前来说必须加
|
||||
//2.返回值 没有返回值填void 可以填写任意类型变量
|
||||
//3.函数名 帕斯卡命名法
|
||||
//4.参数可以是任意多个,可以加ref和out作为修饰词
|
||||
//5.如果返回值不是void 那么必须有return对应类型的内容 return可以直接打断后续代码的运行
|
||||
#endregion
|
||||
|
||||
#region 知识点二 变长参数关键词
|
||||
// 举例 函数要计算 n个整数的和
|
||||
// 在常规写法中 static int Sum(int a, int b, ......)
|
||||
// 需要手写很多 或 不确定个变量
|
||||
|
||||
// 变成参数关键字 params
|
||||
static int Sum(params int[] arr)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
sum += arr[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
//params int[]意味着可以传入n个int参数 n可以等于0 传入的参数会在arr数组中
|
||||
//注意:
|
||||
//1.params关键字后面必须为数组
|
||||
//2.数组的类型可以时任意的类型
|
||||
|
||||
//3.函数参数可以有 别的参数 params关键字修饰的参数
|
||||
//4.函数参数中只能最多出现一个params关键字 并且一定是在最后一组参数 前面可以有任意个其他参数
|
||||
//示例:static void Eat(string name, int a, params int[] arr) { }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 知识点三 参数默认值
|
||||
//有参数默认值的参数 一般称为可选参数
|
||||
//作用是 当调用函数时可以不传入参数,不穿就会使用默认值,作为参数的默认值
|
||||
static void Speak(string str = "什么都没说")
|
||||
{
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
|
||||
//注意:
|
||||
//1.支持多参数默认值 每个参数都可以有默认值
|
||||
//2.如果要混用 可选参数 必须写在普通参数后面
|
||||
//示例:static void Speak2(string test, string name="123",string str = "什么都没说") { }
|
||||
//第一个参数必须传,第二个第三个可以不传
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Sum();
|
||||
Sum(1,2,3,4,5,6,7,8,9,10);//可以填写无数个参数
|
||||
|
||||
Speak();
|
||||
Speak("传入参数");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,60 @@
|
||||
using System;
|
||||
namespace Lesson
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void SumAndAvg(params int[] num)
|
||||
{
|
||||
if (num.Length == 0)
|
||||
{
|
||||
Console.WriteLine("没有东西");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
int sum = 0, avg;
|
||||
for (int i = 0; i < num.Length; i++)
|
||||
{
|
||||
sum += num[i];
|
||||
}
|
||||
avg = sum / num.Length;
|
||||
Console.WriteLine("总和为:" + sum);
|
||||
Console.WriteLine("平均为:" + avg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void Calc(params int[] arr)
|
||||
{
|
||||
if(arr.Length == 0)
|
||||
{
|
||||
Console.WriteLine("没有东西");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
int sum1 = 0, sum2 = 0;
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
if (arr[i] % 2 == 0)
|
||||
{
|
||||
sum1 += arr[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
sum2 += arr[i];
|
||||
}
|
||||
}
|
||||
Console.WriteLine("奇数合:"+sum2);
|
||||
Console.WriteLine("偶数合:"+sum1);
|
||||
}
|
||||
}
|
||||
static void Main(string[] args)
|
||||
{
|
||||
SumAndAvg();
|
||||
SumAndAvg(1,2,3,4,5,6,7,8,9,10);
|
||||
Calc();
|
||||
Calc(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
namespace Lesson
|
||||
{
|
||||
class Program
|
||||
{
|
||||
#region 知识点一
|
||||
#endregion
|
||||
|
||||
#region 知识点二
|
||||
#endregion
|
||||
|
||||
#region 知识点三
|
||||
#endregion
|
||||
|
||||
#region 知识点四
|
||||
#endregion
|
||||
|
||||
#region 知识点五
|
||||
#endregion
|
||||
|
||||
#region 知识点六
|
||||
#endregion
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user