diff --git a/C#入门/Csharp入门.sln b/C#入门/Csharp入门.sln new file mode 100644 index 0000000..abf3241 --- /dev/null +++ b/C#入门/Csharp入门.sln @@ -0,0 +1,43 @@ + +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 diff --git a/C#入门/Lession1练习题/Lesson1练习题.csproj b/C#入门/Lession1练习题/Lesson1练习题.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/C#入门/Lession1练习题/Lesson1练习题.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/C#入门/Lession1练习题/Program.cs b/C#入门/Lession1练习题/Program.cs new file mode 100644 index 0000000..81ad2d9 --- /dev/null +++ b/C#入门/Lession1练习题/Program.cs @@ -0,0 +1,17 @@ +using System; + +namespace 练习题 +{ + class program + { + static void Main(string[] args) + { + Console.WriteLine("*************"); + for (int i = 0; i < 10; i++) + { + Console.WriteLine("* *"); + } + Console.WriteLine("*************"); + } + } +} \ No newline at end of file diff --git a/C#入门/Lesson2变量/Lesson2变量.csproj b/C#入门/Lesson2变量/Lesson2变量.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/C#入门/Lesson2变量/Lesson2变量.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/C#入门/Lesson2变量/Program.cs b/C#入门/Lesson2变量/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/C#入门/Lesson2变量/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/C#入门/lesson1/Lesson1注释&输入输出.csproj b/C#入门/lesson1/Lesson1注释&输入输出.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/C#入门/lesson1/Lesson1注释&输入输出.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/C#入门/lesson1/Program.cs b/C#入门/lesson1/Program.cs new file mode 100644 index 0000000..64d2020 --- /dev/null +++ b/C#入门/lesson1/Program.cs @@ -0,0 +1,40 @@ +//双杠注释 +using System; + +namespace Lession1 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello world"); + //writeline是输出后换行 + Console.WriteLine("你好"); + //wirte是输出后不换行 + Console.Write("请输入一些东西:"); + //这是输入一行东西,不按回车不算结束 + Console.ReadLine(); + Console.WriteLine("输入完成"); + Console.Write("请输入一些东西:"); + //检测用户是否按键,只要按了任意一个按键就算结束 + Console.ReadKey(); + Console.WriteLine("输入完成"); + } + } +} + +/*多杠注释 + * + * + */ + + +///三杠注释 +/// +///类 +/// +//Console.WriteLine("你好!"); + + +//Ctrl + K + U取消注释 +//Ctrl + K + C注释快捷键 \ No newline at end of file diff --git a/C#入门/test1/Program.cs b/C#入门/test1/Program.cs new file mode 100644 index 0000000..9c3f610 --- /dev/null +++ b/C#入门/test1/Program.cs @@ -0,0 +1,13 @@ +using System; + +namespace 测试项目 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("hello world"); + } + } +} + \ No newline at end of file diff --git a/C#入门/test1/test1.csproj b/C#入门/test1/test1.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/C#入门/test1/test1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/C#核心/C#核心.sln b/C#核心/C#核心.sln new file mode 100644 index 0000000..7f6507e --- /dev/null +++ b/C#核心/C#核心.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36202.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{B02A4395-F066-4E9C-96EB-C3A8244711A8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson10_封装-运算符重载练习", "Lesson10_封装-运算符重载\Lesson10_封装-运算符重载练习.csproj", "{0AF1A6D3-2B1A-4F58-91A1-9E71CD4C7289}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson10_封装-运算符重载", "Lesson10_封装-运算符重载联系\Lesson10_封装-运算符重载.csproj", "{DEE2177C-8552-488D-A36A-A47B8547580D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson11_内部类和分部类", "Lesson11_内部类和分部类\Lesson11_内部类和分部类.csproj", "{51A60C77-3609-42BD-B0D9-83E1B61B6E69}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B02A4395-F066-4E9C-96EB-C3A8244711A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B02A4395-F066-4E9C-96EB-C3A8244711A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B02A4395-F066-4E9C-96EB-C3A8244711A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B02A4395-F066-4E9C-96EB-C3A8244711A8}.Release|Any CPU.Build.0 = Release|Any CPU + {0AF1A6D3-2B1A-4F58-91A1-9E71CD4C7289}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0AF1A6D3-2B1A-4F58-91A1-9E71CD4C7289}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0AF1A6D3-2B1A-4F58-91A1-9E71CD4C7289}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0AF1A6D3-2B1A-4F58-91A1-9E71CD4C7289}.Release|Any CPU.Build.0 = Release|Any CPU + {DEE2177C-8552-488D-A36A-A47B8547580D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEE2177C-8552-488D-A36A-A47B8547580D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DEE2177C-8552-488D-A36A-A47B8547580D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DEE2177C-8552-488D-A36A-A47B8547580D}.Release|Any CPU.Build.0 = Release|Any CPU + {51A60C77-3609-42BD-B0D9-83E1B61B6E69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {51A60C77-3609-42BD-B0D9-83E1B61B6E69}.Debug|Any CPU.Build.0 = Debug|Any CPU + {51A60C77-3609-42BD-B0D9-83E1B61B6E69}.Release|Any CPU.ActiveCfg = Release|Any CPU + {51A60C77-3609-42BD-B0D9-83E1B61B6E69}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9DF28788-E99D-4F28-8968-F7C213A855D1} + EndGlobalSection +EndGlobal diff --git a/C#核心/Lesson10_封装-运算符重载/Lesson10_封装-运算符重载练习.csproj b/C#核心/Lesson10_封装-运算符重载/Lesson10_封装-运算符重载练习.csproj new file mode 100644 index 0000000..47dd2f0 --- /dev/null +++ b/C#核心/Lesson10_封装-运算符重载/Lesson10_封装-运算符重载练习.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + Lesson10_封装_运算符重载 + enable + enable + + + diff --git a/C#核心/Lesson10_封装-运算符重载/Program.cs b/C#核心/Lesson10_封装-运算符重载/Program.cs new file mode 100644 index 0000000..21fa0f8 --- /dev/null +++ b/C#核心/Lesson10_封装-运算符重载/Program.cs @@ -0,0 +1,126 @@ +using System.Numerics; +using System.Runtime.Intrinsics; + +namespace Lesson10_封装_运算符重载 +{ + //class Vector + //{ + // public int x; + // public int y; + // public Vector(int x,int y) + // { + // this.x = x; + // this.y = y; + // } + // public static bool operator ==(Vector a, Vector b) + // { + // if (a.x == b.x && a.y == b.y) + // { + // return true; + // } + // else + // { + // return false; + // } + // } + // public static bool operator !=(Vector a, Vector b) + // { + // if (a.x != b.x && a.y != b.y) + // { + // return true; + // } + // else + // { + // return false; + // } + // } + //} + struct Position + { + int x; + int y; + + public Position(int x,int y) + { + this.x = x; + this.y = y; + } + public static bool operator ==(Position a, Position b) + { + if (a.x == b.x && a.y == b.y) + { + return true; + } + else + { + return false; + } + } + public static bool operator !=(Position a, Position b) + { + if (a.x != b.x && a.y != b.y) + { + return true; + } + else + { + return false; + } + } + } + class Vector3 + { + public int x,y,z; + public Vector3() + { + x = 0; + y = 0; + z = 0; + } + public Vector3(int x,int y,int z) + { + this.x = x; + this.y = y; + this.z = z; + } + public static Vector3 operator +(Vector3 a,Vector3 b) + { + Vector3 vector = new Vector3(); + vector.x = a.x + b.x; + vector.y = a.y + b.y; + vector.z = a.z + b.z; + return vector; + } + public static Vector3 operator -(Vector3 a, Vector3 b)//一步到位写法 + { + return new Vector3(a.x-b.x,a.y-b.y,a.z-b.z); + } + public static Vector3 operator *(Vector3 a, int b) + { + Vector3 vector = new Vector3(); + vector.x = a.x * b; + vector.y = a.y * b; + vector.z = a.z * b; + return vector; + } + } + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + Position p1 = new Position(1, 2); + Position p2 = new Position(1, 2); + Console.WriteLine(p1 == p2); + Console.WriteLine(p1 != p2); + Vector3 v1 = new Vector3(2,2,2); + Vector3 v2 = new Vector3(1,1,1); + Vector3 v3 = v1 + v2; + Vector3 v4 = v1 - v2; + Vector3 v5 = v1 * 2; + Console.WriteLine(v3.x); + Console.WriteLine(v4.x); + Console.WriteLine(v5.x); + } + } +} diff --git a/C#核心/Lesson10_封装-运算符重载联系/Lesson10_封装-运算符重载.csproj b/C#核心/Lesson10_封装-运算符重载联系/Lesson10_封装-运算符重载.csproj new file mode 100644 index 0000000..a29b338 --- /dev/null +++ b/C#核心/Lesson10_封装-运算符重载联系/Lesson10_封装-运算符重载.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + Lesson10_封装_运算符重载联系 + enable + enable + + + diff --git a/C#核心/Lesson10_封装-运算符重载联系/Program.cs b/C#核心/Lesson10_封装-运算符重载联系/Program.cs new file mode 100644 index 0000000..cc31fc0 --- /dev/null +++ b/C#核心/Lesson10_封装-运算符重载联系/Program.cs @@ -0,0 +1,103 @@ +namespace Lesson10_封装_运算符重载联系 +{ + #region 知识点一 基本概念 + //概念 + //让自定义类和结构体 + //能够使用运算符 + + //使用关键字 + //operator + + //特点 + //1.一定是一个公共的静态方法 + //2.返回值写在operator前 + //3.逻辑处理自定义 + + //作用 + //让自定义类和结构体对象可以进行运算 + //注意 + //1.条件运算符需要承兑实现 + //2.一个符号可以多个重载 + //3.不能使用ref和out + #endregion + + #region 知识点二 基本语法 + //public static 返回值类型 operator 运算符(参数列表){} + #endregion + + #region 知识点三 实例 + class Point + { + public int x; + public int y; + public static Point operator +(Point p1,Point p2) + { + Point p = new Point(); + p.x = p1.x + p2.x; + p.y = p1.y + p2.y; + return p; + } + public static Point operator +(Point p1, int value) + { + Point p = new Point(); + p.x = p1.x + value; + p.y = p1.y + value; + return p; + } + public static Point operator +(int value, Point p1) + { + Point p = new Point(); + p.x = p1.x + value; + p.y = p1.y + value; + return p; + } + } + #endregion + + #region 知识点五 可重载和不可重载的运算符 + #region 可重载 + //注意运算所需的参数数量 + //算术运算符 + //- * / % ++ --都可以 + + //逻辑运算符 + //!可以 + + //位运算符 + //| & ^ ~ >> << 可以 + + //条件运算符 + //>= <= == < >需要成对出现(写了>的就要写<的) + //一般返回值都是bool也可以是其他值 + #endregion + #region 不可重载 + //逻辑与&& 逻辑或|| + //索引符[] + //强转运算符() + //特殊运算符 + //点. 三目运算符 ? : 赋值号= + #endregion + #endregion + + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + #region 知识点四 使用 + Point p = new Point(); + p.x = 1; + p.y = 1; + Console.WriteLine(p.x+" "+p.y); + Point p2 = new Point(); + p2.x = 2; + p2.y = 2; + Console.WriteLine(p2.x + " " + p2.y); + Point p3 = p + p2; + Console.WriteLine(p3.x + " " + p3.y); + Point p4 = p3 + 2; + Point p5 = 3 + p4; + #endregion + } + } +} diff --git a/C#核心/Lesson11_内部类和分部类/Lesson11_内部类和分部类.csproj b/C#核心/Lesson11_内部类和分部类/Lesson11_内部类和分部类.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/C#核心/Lesson11_内部类和分部类/Lesson11_内部类和分部类.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/C#核心/Lesson11_内部类和分部类/Program.cs b/C#核心/Lesson11_内部类和分部类/Program.cs new file mode 100644 index 0000000..1cda043 --- /dev/null +++ b/C#核心/Lesson11_内部类和分部类/Program.cs @@ -0,0 +1,10 @@ +namespace Lesson11_内部类和分部类 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} diff --git a/C#核心/test/Program.cs b/C#核心/test/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/C#核心/test/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/C#核心/test/test.csproj b/C#核心/test/test.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/C#核心/test/test.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + +