From 910a5dbdced65a825593d61c98fe979da37de7ba Mon Sep 17 00:00:00 2001 From: xiaojiuxu <2997735823@qq.com> Date: Mon, 21 Jun 2021 23:16:00 +0800 Subject: [PATCH] asdf --- .../Program.cs" | 104 ++++++++++++ .../Animal.cs" | 34 ++++ .../Cat.cs" | 25 +++ .../Dog.cs" | 20 +++ .../Duck.cs" | 21 +++ .../IClimbTree.cs" | 13 ++ .../ISwim.cs" | 13 ++ .../Monkey.cs" | 24 +++ .../Program.cs" | 45 +++++ .../Batmobile.cs" | 21 +++ .../Cars.cs" | 34 ++++ .../IFly.cs" | 13 ++ .../Program.cs" | 26 +++ .../Animal.cs" | 25 +++ .../Bird.cs" | 38 +++++ .../IFly.cs" | 15 ++ .../Plane.cs" | 32 ++++ .../Program.cs" | 44 +++++ .../Superman.cs" | 32 ++++ .../Vehicle.cs" | 20 +++ .../Calculate.cs" | 56 +++++++ .../Program.cs" | 66 ++++++++ .../SumUtils.cs" | 48 ++++++ .../Employee.cs" | 36 ++++ .../Program.cs" | 19 +++ .../Program.cs" | 157 ++++++++++++++++++ .../SortAge.cs" | 16 ++ .../SortName.cs" | 16 ++ .../SortNum.cs" | 16 ++ .../Students.cs" | 31 ++++ .../Library.cs" | 87 ++++++++++ .../Program.cs" | 86 ++++++++++ .../Students.cs" | 86 ++++++++++ .../UserInfo.cs" | 31 ++++ 34 files changed, 1350 insertions(+) create mode 100644 "\345\217\266\347\234\237/\345\255\227\347\254\246\344\270\262\345\270\270\347\224\250\346\226\271\346\263\225\347\273\203\344\271\240/Program.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Animal.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Cat.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Dog.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Duck.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/IClimbTree.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/ISwim.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Monkey.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Program.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Batmobile.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Cars.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/IFly.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Program.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Animal.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Bird.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/IFly.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Plane.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Program.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Superman.cs" create mode 100644 "\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Vehicle.cs" create mode 100644 "\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/Calculate.cs" create mode 100644 "\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/Program.cs" create mode 100644 "\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/SumUtils.cs" create mode 100644 "\345\217\266\347\234\237/\346\236\204\351\200\240\346\226\271\346\263\225/Employee.cs" create mode 100644 "\345\217\266\347\234\237/\346\236\204\351\200\240\346\226\271\346\263\225/Program.cs" create mode 100644 "\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/Program.cs" create mode 100644 "\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortAge.cs" create mode 100644 "\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortName.cs" create mode 100644 "\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortNum.cs" create mode 100644 "\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/Students.cs" create mode 100644 "\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Library.cs" create mode 100644 "\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Program.cs" create mode 100644 "\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Students.cs" create mode 100644 "\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/UserInfo.cs" diff --git "a/\345\217\266\347\234\237/\345\255\227\347\254\246\344\270\262\345\270\270\347\224\250\346\226\271\346\263\225\347\273\203\344\271\240/Program.cs" "b/\345\217\266\347\234\237/\345\255\227\347\254\246\344\270\262\345\270\270\347\224\250\346\226\271\346\263\225\347\273\203\344\271\240/Program.cs" new file mode 100644 index 0000000..dec57e4 --- /dev/null +++ "b/\345\217\266\347\234\237/\345\255\227\347\254\246\344\270\262\345\270\270\347\224\250\346\226\271\346\263\225\347\273\203\344\271\240/Program.cs" @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp5 +{ + class Program + { +// 一、统计下面一段文字中“类”字和“码”的个数。 + +//与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。 + +//1、使用循环遍历的方法来实现。 +//2、使用Replace方法来实现。 +//3、使用Split()方法来实现。 + + + +//二、 +//C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。 + +//去掉上面一段文字的所有空格,并统计空格数。 + + static void Main(string[] args) + { + Test1(); + Test2(); + Test3(); + Test4(); + } + + private static void Test4() + { + string str = "C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。"; + int num = 0; + string str2 = ""; + + for (int i = 0; i < str.Length; i++) + { + str2 = str.Replace(" ",""); + num++; + } + Console.WriteLine(str2); + Console.WriteLine($"有{num}"); + } + + private static void Test3() + { + string str = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + int maNum = 0; + int leiNum = 0; + + string[] maArr = str.Split('码'); + string[] leiArr = str.Split('类'); + + maNum = maArr.Length - 1; + leiNum = leiArr.Length - 1; + + Console.WriteLine($"码{maNum},类{leiNum}"); + } + + private static void Test2() + { + string str = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + int maNum = 0; + int leiNum = 0; + string maStr = ""; + string leiStr = ""; + + for (int i = 0; i < str.Length; i++) + { + maStr = str.Replace("码", ""); + leiStr = str.Replace("类", ""); + } + + maNum = str.Length - maStr.Length; + leiNum = str.Length - leiStr.Length; + + Console.WriteLine($"码{maNum},类{leiNum}"); + } + + private static void Test1() + { + string str = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + int maNum = 0; + int leiNum = 0; + + foreach (char item in str) + { + if (item == '码') + { + maNum++; + } + if (item == '类') + { + leiNum++; + } + } + Console.WriteLine($"码{maNum},类{leiNum}"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Animal.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Animal.cs" new file mode 100644 index 0000000..79385fa --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Animal.cs" @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + class Animal + { + private string name; + public string Name + { + get + { + return this.name; + } + set + { + this.name = value; + } + } + + public Animal(string name) + { + this.name = name; + } + + public void Eat() + { + Console.WriteLine($"{name}吃"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Cat.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Cat.cs" new file mode 100644 index 0000000..4510b05 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Cat.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + class Cat : Animal,ISwim,IClimbTree + { + public Cat(string name) : base(name) + { + } + + public void ClimbTree() + { + Console.WriteLine($"{this.Name}爬树"); + } + + public void Swim() + { + Console.WriteLine($"{this.Name}游泳"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Dog.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Dog.cs" new file mode 100644 index 0000000..c29e610 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Dog.cs" @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + class Dog:Animal,ISwim + { + public Dog(string name):base(name) + { + + } + public void Swim() + { + Console.WriteLine($"{this.Name}游泳"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Duck.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Duck.cs" new file mode 100644 index 0000000..4dedd2d --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Duck.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + class Duck:Animal,ISwim + { + public Duck(string name) : base(name) + { + + } + + public void Swim() + { + Console.WriteLine($"{this.Name}游泳"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/IClimbTree.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/IClimbTree.cs" new file mode 100644 index 0000000..613d892 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/IClimbTree.cs" @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + interface IClimbTree + { + void ClimbTree(); + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/ISwim.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/ISwim.cs" new file mode 100644 index 0000000..874de80 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/ISwim.cs" @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + interface ISwim + { + void Swim(); + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Monkey.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Monkey.cs" new file mode 100644 index 0000000..556c72b --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Monkey.cs" @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + class Monkey:Animal,ISwim,IClimbTree + { + public Monkey(string name):base(name) + { + + } + public void Swim() + { + Console.WriteLine($"{this.Name}游泳"); + } + public void ClimbTree() + { + Console.WriteLine($"{this.Name}爬树"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Program.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Program.cs" new file mode 100644 index 0000000..c1abd9d --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\347\214\253\343\200\201\347\213\227\343\200\201\351\270\255\343\200\201\347\214\264\357\274\214\357\274\210\345\220\203\343\200\201\346\270\270\346\263\263\343\200\201\347\210\254\346\240\221\357\274\211/Program.cs" @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + class Program + { +// 1、猫、狗、鸭、猴,(吃、游泳、爬树) +//所有动物都有吃的方法 +//狗和鸭会游泳,不会爬树 +//猫和猴不会游泳会爬树 +//将吃的方法定义在父类方法中,将游泳和爬树的技能定义为接口 +//所有子类继承父类后,再去继承相应的接口实现技能 + + static void Main(string[] args) + { + Cat cat = new Cat("猫"); + cat.Eat(); + cat.Swim(); + cat.ClimbTree(); + + Console.WriteLine("---------------------"); + + Monkey monkey = new Monkey("猴子"); + monkey.Eat(); + monkey.Swim(); + monkey.ClimbTree(); + + Console.WriteLine("---------------------"); + + Duck duck = new Duck("鸭子"); + duck.Eat(); + duck.Swim(); + + Console.WriteLine("---------------------"); + + Dog dog = new Dog("狗"); + dog.Eat(); + dog.Swim(); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Batmobile.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Batmobile.cs" new file mode 100644 index 0000000..7af0d01 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Batmobile.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + class Batmobile:Cars,IFly + { + public Batmobile(string brand):base(brand) + { + + } + + public void Fly() + { + Console.WriteLine($"{Brand}会飞"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Cars.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Cars.cs" new file mode 100644 index 0000000..97afea7 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Cars.cs" @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + class Cars + { + private string brand; + public string Brand + { + get + { + return this.brand; + } + set + { + this.brand = value; + } + } + + public Cars(string brand) + { + this.Brand = brand; + } + + public void Run() + { + Console.WriteLine($"{brand}会跑"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/IFly.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/IFly.cs" new file mode 100644 index 0000000..68162cd --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/IFly.cs" @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + interface IFly + { + void Fly(); + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Program.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Program.cs" new file mode 100644 index 0000000..4f83fcb --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\350\235\231\350\235\240\346\210\230\350\275\246\347\232\204\344\276\213\345\255\220/Program.cs" @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + class Program + { +// 定义一个父类表示车的共同属性特征行为:品牌名Brand, +// 会跑Run方法 +//定义一个飞的功能接口类IFly:定义飞的方法Fly +//然后定义蝙蝠战车类继承Cat类和飞的接口 +//在主方法实例化蝙蝠战车的对象,并为品牌名赋值, +//调用跑和飞的方法 + + static void Main(string[] args) + { + Batmobile batmobile = new Batmobile("蝙蝠战车"); + + batmobile.Fly(); + batmobile.Run(); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Animal.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Animal.cs" new file mode 100644 index 0000000..327a5b9 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Animal.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class Animal + { + private string name; + + public string Name { get => name; set => name = value; } + + public Animal(string name) + { + this.Name = name; + } + + public void Eat() + { + Console.WriteLine($"{name}在吃"); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Bird.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Bird.cs" new file mode 100644 index 0000000..2cd7d58 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Bird.cs" @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class Bird : Animal,IFly + { + public Bird(string name) : base(name) + { + } + public void Lay() + { + Console.WriteLine($"{Name}在下蛋"); + } + + public void Flying() + { + Console.WriteLine($"{Name}起飞"); + + } + + public void Land() + { + Console.WriteLine($"{Name}飞行中"); + + } + + + public void TakeOff() + { + Console.WriteLine($"{Name}降落"); + + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/IFly.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/IFly.cs" new file mode 100644 index 0000000..d46293d --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/IFly.cs" @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + interface IFly + { + void TakeOff(); + void Flying(); + void Land(); + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Plane.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Plane.cs" new file mode 100644 index 0000000..893bdbb --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Plane.cs" @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class Plane : Vehicle,IFly + { + public Plane(string brand) : base(brand) + { + } + + public void Flying() + { + Console.WriteLine($"{Brand}起飞"); + } + + public void Land() + { + Console.WriteLine($"{Brand}飞行中"); + + } + + public void TakeOff() + { + Console.WriteLine($"{Brand}降落"); + + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Program.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Program.cs" new file mode 100644 index 0000000..4b3f6f4 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Program.cs" @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class Program + { +// 1. 飞机是交通工具类,有运输载人的功能; +//2. 小鸟和超人都是动物类,都有吃的方法; +//小鸟有自己的特有方法,下蛋; +//3. 超人、小鸟、飞机都有飞的功能,可以定义飞的接口; +//飞的接口有起飞、飞行中、着陆的方法; +//4. 超人、小鸟、飞机除了继承各自的父类后, +//还要继承飞的接口,实现飞的接口的方法; + + static void Main(string[] args) + { + Superman superman = new Superman("超人"); + superman.Eat(); + superman.TakeOff(); + superman.Flying(); + superman.Land(); + + Console.WriteLine("-------------------------"); + + Bird bird = new Bird("鸟"); + bird.Eat(); + bird.Lay(); + bird.TakeOff(); + bird.Flying(); + bird.Land(); + + Console.WriteLine("-------------------------"); + + Plane plane = new Plane("飞机"); + plane.TakeOff(); + plane.Flying(); + plane.Land(); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Superman.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Superman.cs" new file mode 100644 index 0000000..a166400 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Superman.cs" @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class Superman : Animal,IFly + { + public Superman(string name) : base(name) + { + } + + public void Flying() + { + Console.WriteLine($"{Name}起飞"); + } + + public void Land() + { + Console.WriteLine($"{Name}飞行中"); + + } + + public void TakeOff() + { + Console.WriteLine($"{Name}降落"); + + } + } +} diff --git "a/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Vehicle.cs" "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Vehicle.cs" new file mode 100644 index 0000000..ea0e30e --- /dev/null +++ "b/\345\217\266\347\234\237/\346\216\245\345\217\243\344\275\234\344\270\232/\351\243\236\346\234\272\343\200\201\351\270\237\343\200\201\350\266\205\344\272\272/Vehicle.cs" @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class Vehicle + { + private string brand; + + public string Brand { get => brand; set => brand = value; } + + public Vehicle(string brand) + { + this.Brand = brand; + } + } +} diff --git "a/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/Calculate.cs" "b/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/Calculate.cs" new file mode 100644 index 0000000..d33a39d --- /dev/null +++ "b/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/Calculate.cs" @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + class Calculate + { + private double longer; + private double wide; + + public double Longer + { + get + { + return this.longer; + } + set + { + this.longer = value; + } + } + public double Wide + { + get + { + return this.wide; + } + set + { + this.wide = value; + } + } + + /// + /// 计算长方形的面积 + /// + /// 长 + /// 宽 + public void Area(double longer,double wide) + { + Console.WriteLine("该长方形的面积为:"+(longer * wide)); + } + + /// + /// 计算圆的面积 + /// + /// 半径 + public void Area(double longer) + { + Console.WriteLine("该圆的面积为:" + (longer * longer * 3.14)); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/Program.cs" "b/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/Program.cs" new file mode 100644 index 0000000..39b87c6 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/Program.cs" @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + class Program + { + +//1. 定义一个计算图形面积的类,类中定义2个计算面积的方法(重载,方法名相同), + //分别计算圆面积和长方形面积两个方法。 +//提示:计算圆的面积传半径,计算长方形面积传长和宽。 + +//2.创建一个名为计算工具类 SumUtils,在类中定义4个方法: +// 计算两个整数相加、 +// 两个小数相加、 +// 两个字符串相加、 +// 以及从 1 到指定整数的和的方法。 +//在 Main 方法中分别调用定义好的方法。 + +//提示:根据题目要求,分别定义 3 个带两个参数的方法,以及一个带一个整型参数的方法, +// 四个方法名相同。 + static void Main(string[] args) + { + Test1(); + Console.WriteLine(); + Test2(); + } + + private static void Test2() + { + SumUtils sum = new SumUtils(); + sum.sum(1,2); + sum.sum(1.2, 2.1); + sum.sum("1", "2"); + sum.sum(12); + } + + static void Test1() + { + Calculate calculate = new Calculate(); + Console.WriteLine("请选择您要计算的图形1、长方形;2、圆形"); + int index = int.Parse(Console.ReadLine()); + + switch (index) + { + case 1: + Console.WriteLine("请输入长"); + int longer = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入宽"); + int wide = int.Parse(Console.ReadLine()); + calculate.Area(longer,wide); + break; + case 2: + Console.WriteLine("请输入半径"); + int ban = int.Parse(Console.ReadLine()); + calculate.Area(ban); + break; + default: + break; + } + } + } +} diff --git "a/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/SumUtils.cs" "b/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/SumUtils.cs" new file mode 100644 index 0000000..1db5059 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\226\271\346\263\225\351\207\215\350\275\275/SumUtils.cs" @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + class SumUtils + { + private int int1; + private int int2; + private string string1; + private string string2; + private double double1; + private double double2; + + public int Int1 { get => int1; set => int1 = value; } + public int Int2 { get => int2; set => int2 = value; } + public string String1 { get => string1; set => string1 = value; } + public string String2 { get => string2; set => string2 = value; } + public double Double1 { get => double1; set => double1 = value; } + public double Double2 { get => double2; set => double2 = value; } + + public void sum(int int1,int int2) + { + Console.WriteLine(int1 + int2); + } + public void sum(double double1, double double2) + { + Console.WriteLine(double1 + double2); + } + public void sum(string string1, string string2) + { + Console.WriteLine(string1 + string2); + } + public void sum(int int1) + { + int sum = 0; + for (int i = 1; i < int1; i++) + { + sum = sum + i; + } + + Console.WriteLine(sum); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\236\204\351\200\240\346\226\271\346\263\225/Employee.cs" "b/\345\217\266\347\234\237/\346\236\204\351\200\240\346\226\271\346\263\225/Employee.cs" new file mode 100644 index 0000000..439fdb8 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\236\204\351\200\240\346\226\271\346\263\225/Employee.cs" @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class Employee + { + private int num; + private string name; + private string sex; + private string education; + private string section; + + public int Num { get => num; set => num = value; } + public string Name { get => name; set => name = value; } + public string Sex { get => sex; set => sex = value; } + public string Education { get => education; set => education = value; } + + public Employee() + { + this.education = "专科"; + } + + public Employee(int num, string name, string sex, string education, string section) + { + this.num = num; + this.name = name; + this.sex = sex; + this.education = education; + this.section = section; + } + } +} diff --git "a/\345\217\266\347\234\237/\346\236\204\351\200\240\346\226\271\346\263\225/Program.cs" "b/\345\217\266\347\234\237/\346\236\204\351\200\240\346\226\271\346\263\225/Program.cs" new file mode 100644 index 0000000..c5cade1 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\236\204\351\200\240\346\226\271\346\263\225/Program.cs" @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class Program + { +// 定义一个员工类,存放用户的工号、姓名、性别、学历和部门信息; +//定义两个构造函数: +//一个是无参构造函数,学历默认为专科; +//一个有参构造函数,根据参数对类的属性进行初始化。 + static void Main(string[] args) + { + } + } +} diff --git "a/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/Program.cs" "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/Program.cs" new file mode 100644 index 0000000..226d1f5 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/Program.cs" @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp5 +{ + class Program + { +// 添加3个类,分别实现 IComparer接口, +// 实现对Student类的三个字段的排序。 +//1、学生类:学号、姓名、年龄 +//2、请选择:1、添加学生信息。2、删除学生信息 2、查询学生信息。 +//3、重复的学号不能添加。 +//4、查询学生信息功能中有:1、查询所有(按学号排序) +//2、查询所有(按姓名排序),2、查询所有(按年龄排序) +//4、按学号查询(查没有,则打印查无此学生)5、退出 + + static void Main(string[] args) + { + List list = new List(); + + Students s1 = new Students(1,"张三",25); + Students s2 = new Students(2, "李四", 19); + Students s3 = new Students(3, "王五", 16); + + list.Add(s1); + list.Add(s2); + list.Add(s3); + + while (true) + { + Console.WriteLine("1、添加学生信息 2、删除学生信息 3、查询学生信息"); + int key1 = int.Parse(Console.ReadLine()); + + switch (key1) + { + case 1: + Console.WriteLine("请输入新学生的学号"); + int addNum = int.Parse(Console.ReadLine()); + bool index1 = true; + + foreach (Students item in list) + { + if (addNum == item.Num) + { + Console.WriteLine("学号重复"); + index1 = false; + break; + } + } + + if (index1) + { + Console.WriteLine("新学生的姓名"); + string addName = Console.ReadLine(); + + Console.WriteLine("新学生的年龄"); + int addAge = int.Parse(Console.ReadLine()); + + list.Add(new Students(addNum, addName, addAge)); + + break; + } + break; + case 2: + Console.WriteLine("请输入想要删除的学生的学号"); + int delNum = int.Parse(Console.ReadLine()); + bool index2 = true; + + foreach (Students item in list) + { + if (delNum == item.Num) + { + list.Remove(item); + index2 = false; + break; + } + } + + if (index2) + { + Console.WriteLine("查无该学生"); + } + break; + case 3: + Console.WriteLine("1、查询所有(按学号排序)2、查询所有(按姓名排序),2、查询所有(按年龄排序)4、按学号查询(查没有,则打印查无此学生)5、退出"); + int key2 = int.Parse(Console.ReadLine()); + IComparer comparer; + + switch (key2) + { + case 1: + comparer = new SortNum(); + + list.Sort(comparer); + + foreach (Students item in list) + { + Console.WriteLine(item.ToString()); + } + break; + case 2: + comparer = new SortName(); + + list.Sort(comparer); + + foreach (Students item in list) + { + Console.WriteLine(item.ToString()); + } + break; + case 3: + comparer = new SortAge(); + + list.Sort(comparer); + + foreach (Students item in list) + { + Console.WriteLine(item.ToString()); + } + break; + case 4: + Console.WriteLine("请输入想查询的学号"); + int LookNum = int.Parse(Console.ReadLine()); + bool index3 = true; + + foreach (Students item in list) + { + if (LookNum == item.Num) + { + Console.WriteLine(item.ToString()); + index3 = false; + break; + } + } + + if (index3) + { + Console.WriteLine("查无该学生"); + } + break; + case 5: + Console.WriteLine("退出成功"); + break; + default: + break; + } + break; + default: + break; + } + } + } + } +} diff --git "a/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortAge.cs" "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortAge.cs" new file mode 100644 index 0000000..d8b904b --- /dev/null +++ "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortAge.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp5 +{ + class SortAge : IComparer + { + public int Compare(Students x, Students y) + { + return x.Age.CompareTo(y.Age); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortName.cs" "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortName.cs" new file mode 100644 index 0000000..e167706 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortName.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp5 +{ + class SortName : IComparer + { + public int Compare(Students x, Students y) + { + return x.Name.CompareTo(y.Name); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortNum.cs" "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortNum.cs" new file mode 100644 index 0000000..24434cf --- /dev/null +++ "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/SortNum.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp5 +{ + class SortNum : IComparer + { + public int Compare(Students x, Students y) + { + return x.Num.CompareTo(y.Num); + } + } +} diff --git "a/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/Students.cs" "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/Students.cs" new file mode 100644 index 0000000..6700c62 --- /dev/null +++ "b/\345\217\266\347\234\237/\346\263\233\345\236\213\351\233\206\345\220\210\347\273\203\344\271\240/Students.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp5 +{ + //学号、姓名、年龄 + class Students + { + private int num; + private string name; + private int age; + + public int Num { get => num; set => num = value; } + public string Name { get => name; set => name = value; } + public int Age { get => age; set => age = value; } + + public Students(int num,string name,int age) + { + this.Num = num; + this.Name = name; + this.Age = age; + } + public override string ToString() + { + return $"{num} {name} {age}"; + } + } +} diff --git "a/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Library.cs" "b/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Library.cs" new file mode 100644 index 0000000..f69923e --- /dev/null +++ "b/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Library.cs" @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + //编号、书名、价格、出版社、作者信息 + class Library + { + private int ibsn; + private string bookName; + private double money; + private string press; + private string author; + + public int Ibsn + { + get + { + return this.ibsn; + } + set + { + this.ibsn = value; + } + } + public string BookName + { + get + { + return this.bookName; + } + set + { + this.bookName = value; + } + } + public double Money + { + get + { + return this.money; + } + set + { + if (value<0) + { + this.money = 0; + } + else + { + this.money = value; + } + } + } + public string Press + { + get + { + return this.press; + } + set + { + this.press = value; + } + } + public string Author + { + get + { + return this.author; + } + set + { + this.author = value; + } + } + + public void ToString() + { + Console.WriteLine($"书编码{this.ibsn},书名{this.bookName},价格{this.money},出版社{this.press},作者{this.author}"); + } + + } +} diff --git "a/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Program.cs" "b/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Program.cs" new file mode 100644 index 0000000..6c6970f --- /dev/null +++ "b/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Program.cs" @@ -0,0 +1,86 @@ +using ConsoleApp1; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp6 +{ + class Program + { + // ## 练习 + + //1. 定义一个用户类,存放用户的账号、用户名和密码属性; + // 在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息;然后在主方法调用输出; + + //2. 定义一个学生类,存放学生的学号、姓名、性别、年龄、专业信息; + // 对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁), + // 该年龄值为0; + // 在学生类中定义一个方法输出学生信息。 + // 在主方法实例化对象,赋值并输出 + + //3.定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; + // 对价格进行赋值限制,小于0价格,赋值为0 + // 在图书类中定义一个方法输出图书信息; + // 在主方法实例化对象,赋值并输出 + static void Main(string[] args) + { + Test1(); + Test2(); + Test3(); + } + + private static void Test3() + { + Library library = new Library(); + Console.WriteLine("书编码"); + library.Ibsn = int.Parse(Console.ReadLine()); + + Console.WriteLine("书名"); + library.BookName = Console.ReadLine(); + + Console.WriteLine("价格"); + library.Money = double.Parse(Console.ReadLine()); + + Console.WriteLine("出版社"); + library.Press = Console.ReadLine(); + + Console.WriteLine("作者"); + library.Author = Console.ReadLine(); + + library.ToString(); + } + + private static void Test2() + { + Students students = new Students(); + Console.WriteLine("学号"); + students.Num = int.Parse(Console.ReadLine()); + Console.WriteLine("姓名"); + students.Name = Console.ReadLine(); + Console.WriteLine("性别"); + students.Sex = Console.ReadLine(); + Console.WriteLine("年龄"); + students.Age = int.Parse(Console.ReadLine()); + Console.WriteLine("专业"); + students.Major = Console.ReadLine(); + + students.ToString(); + + } + + private static void Test1() + { + Console.WriteLine("账号"); + string userAccount = Console.ReadLine(); + Console.WriteLine("用户名"); + string userName = Console.ReadLine(); + Console.WriteLine("密码"); + string userPassword = Console.ReadLine(); + UserInfo userInfo = new UserInfo(userAccount,userName,userPassword); + + userInfo.ToString(); + } + } +} diff --git "a/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Students.cs" "b/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Students.cs" new file mode 100644 index 0000000..c7fabc9 --- /dev/null +++ "b/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/Students.cs" @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + //学号、姓名、性别、年龄、专业信息 + class Students + { + private int num; + private string name; + private string sex; + private int age; + private string major; + + public int Num + { + get + { + return this.num; + } + set + { + this.num = value; + } + } + public string Name + { + get + { + return this.name; + } + set + { + this.name = value; + } + } + public string Sex + { + get + { + return this.sex; + } + set + { + this.sex = value; + } + } + public int Age + { + get + { + return this.age; + } + set + { + if (value < 0 || value > 128) + { + this.age = 0; + } + else + { + this.age = value; + } + } + } + public string Major + { + get + { + return this.major; + } + set + { + this.major = value; + } + } + + public void ToString() + { + Console.WriteLine($"学号{this.num} 姓名{name} 性别{sex} 年龄{age} 专业{major}"); + } + } +} diff --git "a/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/UserInfo.cs" "b/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/UserInfo.cs" new file mode 100644 index 0000000..6145004 --- /dev/null +++ "b/\345\217\266\347\234\237/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/UserInfo.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp6 +{ + class UserInfo + { + private string userName; + private string userAccount; + private string userPassword; + + public string UserName { get => userName; set => userName = value; } + public string UserAccount { get => userAccount; set => userAccount = value; } + public string UserPassword { get => userPassword; set => userPassword = value; } + + public UserInfo(string userAccount,string userName,string userPassword) + { + this.UserAccount = userAccount; + this.UserName = userName; + this.UserPassword = userPassword; + } + + public void ToString() + { + Console.WriteLine($"{this.userName} {this.userAccount} {userPassword}"); + } + } +} -- Gitee