diff --git "a/\351\273\204\345\277\240\347\243\212/1.cs" "b/\351\273\204\345\277\240\347\243\212/1.cs" new file mode 100644 index 0000000000000000000000000000000000000000..1b7b15093f61508e3916273c19987466027f5114 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/1.cs" @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp3 +{ + class Program + { + static void Main(string[] args) + { + // 定义一个用户类,存放用户的账号、用户名和密码属性; + //在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息;然后在主方法调用输出; + Class1 cl = new Class1("哒哒哒", 99); + cl.aa(); + } + } +} diff --git "a/\351\273\204\345\277\240\347\243\212/string.cs" "b/\351\273\204\345\277\240\347\243\212/string.cs" new file mode 100644 index 0000000000000000000000000000000000000000..8a4c92c1b0feef5062d3d0fe62d9917d54bc29d0 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/string.cs" @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + class Program + { + static void Main(string[] args) + { + // 一、统计下面一段文字中“类”字和“码”的个数。 + + //与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。 + + //1、使用循环遍历的方法来实现。 + + + string f = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + int a = 0; + int b = 0; + + for (int i = 0; i < f.Length; i++) + { + + if (f[i] == '类') + { + a++; + } + else if (f[i] == '码') + { + b++; + } + + + } + Console.WriteLine("类的个数" + a); + Console.WriteLine("码的个数" + b); + Console.WriteLine(); + //2、使用Replace方法来实现。 + + f.Replace('类', '雷'); + f.Replace('码', '嘛'); + for (int i = 0; i < f.Length; i++) + { + + if (f[i] == '雷') + { + a++; + } + else if (f[i] == '嘛') + { + b++; + } + } + Console.WriteLine("雷的个数" + a); + Console.WriteLine("嘛的个数" + b); + + Console.WriteLine(); + //3、使用Split()方法来实现。 + string[] e = { "类" }; + string[] re = f.Split(e, StringSplitOptions.None); + Console.WriteLine("类的长度" + (re.Length - 1)); + string[] y = { "码" }; + string[] pp = f.Split(y, StringSplitOptions.None); + Console.WriteLine("妈的长度" + (pp.Length - 1)); + + + //二、 + //C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。 + + //去掉上面一段文字的所有空格,并统计空格数。 + string qq = "C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。"; + string u = qq.Replace(" ", ""); + Console.WriteLine("去空格: "+u); + string[] s= { " " }; + Console.WriteLine(); + string[] c = qq.Split(s, StringSplitOptions.RemoveEmptyEntries); + Console.WriteLine("空格数 :" + (c.Length - 1)); + + + + + } + } +} diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (2)/Class1.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (2)/Class1.cs" new file mode 100644 index 0000000000000000000000000000000000000000..e3ea37531c41655c63266f8e76392ad3bab198c8 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (2)/Class1.cs" @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp5 +{ + class Class1 + { + public string xx = "专科"; + + public int aa; + public int Aa + { + get { return this.aa = aa; } + set + { + if (value<0 ||value>=1000) + { + this.aa = 0; + } + else + { + this.aa = value; + } + } + } + public void ww() + { + Console.WriteLine("年纪{0} 学历{1}", this.Aa,this.xx); + } + } +} diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (2)/Program.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (2)/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..f6973a1363e485115aa6b6625d0035495308547e --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (2)/Program.cs" @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp5 +{ + class Program + { + static void Main(string[] args) + { + Class1 c = new Class1(); + c.Aa = 80; + + c.ww(); + } + } +} diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/Program.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..5ffbfe67317230ef4ef1fb070a4f7a321c1ebe86 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/Program.cs" @@ -0,0 +1,96 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp6 +{ + class Program + { + static void Main(string[] args) + { + Hashtable h = new Hashtable(); + + // 添加3个类,分别实现 IComparer接口,实现对Student类的三个字段的排序。 + //1、学生类:学号、姓名、年龄 + //2、请选择:1、添加学生信息。2、删除学生信息 2、查询学生信息。 + //3、重复的学号不能添加。 + //4、查询学生信息功能中有:1、查询所有(按学号排序)2、查询所有(按姓名排序),2、查询所有(按年龄排序)4、按学号查询(查没有,则打印查无此学生)5、退出 + List list = new List(); + Student stu1 = new Student(); + stu1.aaa = 110; + stu1.name = "磊哥"; + stu1.age = 18; + Student stu2 = new Student(); + stu2.aaa = 110; + stu2.name = "姗姐"; + stu2.age = 18; + Student stu3 = new Student(); + stu3.aaa = 110; + stu3.name = "姚哥"; + stu3.age = 18; + list.Add(stu1); + list.Add(stu2); + list.Add(stu3); + string namee = Console.ReadLine(); + + foreach (Student item in list) + { + if (namee== item.name) + { + Console.WriteLine(item); + + } + + } + int num = Int32.Parse(Console.ReadLine()); + foreach (Student item in list) + { + if (num==item.aaa) + { + list.Remove(item); + Console.WriteLine("删除成功!"); + } + + } + //1、查询所有(按学号排序) + + while (true) + { + Console.WriteLine("1 查询所有(按学号排序)2、查询所有(按姓名排序),3.(按年龄排序)4、按学号查询(查没有,则打印查无此学生)5、(退出)"); + int num1 = int.Parse(Console.ReadLine()); + IComparer comparer; + switch (num1) + { + case 1: + comparer = new numk(); + comparer = new agge(); + comparer = new xuehao(); + break; + case 2: + comparer = new numk(); + break; + case 3: + comparer = new agge(); + break; + case 4: + comparer = new xuehao(); + break; + case 5: + Environment.Exit(0); + break; + default: + break; + + } + list.Sort(comparer); + foreach (Student student in list) + { + Console.WriteLine(student); + } + } + } + } +} diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/Student.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/Student.cs" new file mode 100644 index 0000000000000000000000000000000000000000..031743e00f836a6dff85be9b51bc3774e1cee6b5 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/Student.cs" @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp6 +{ + class Student + { + public int aaa { get; set; } + public string name { get; set; } + public int age { get; set; } + public override string ToString() + { + return $"学号:{aaa},姓名:{name},年龄:{age}"; + } + + } +} diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/num.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/num.cs" new file mode 100644 index 0000000000000000000000000000000000000000..02f8946aed82038d75e612795264785d3a0ca5f6 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/num.cs" @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp6 +{ + class num + { + } +} diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/numk.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/numk.cs" new file mode 100644 index 0000000000000000000000000000000000000000..c755a3c6187da47914e2f5f9bd334000a64dc4eb --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/numk.cs" @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace ConsoleApp6 +{ + internal class numk : IComparer + { + public int Compare(Student x, Student y) + { + return x.name.CompareTo(y.name); + } + } +} \ No newline at end of file diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/xuehao.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/xuehao.cs" new file mode 100644 index 0000000000000000000000000000000000000000..31fbdce805cca786f7319933bece8ce50ae34c83 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271 (3)/xuehao.cs" @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace ConsoleApp6 +{ + internal class xuehao : IComparer + { + public int Compare(Student x, Student y) + { + return x.aaa.CompareTo(y.aaa); + } + } +} \ No newline at end of file diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/Program.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..1854bfbb3da35a567c900c3ec5a058b3e7560055 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/Program.cs" @@ -0,0 +1,28 @@ +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) + { + // 创建一个名为计算工具类 SumUtils,在类中定义4个方法: + // 计算两个整数相加、 + // 两个小数相加、 + // 两个字符串相加、 + // 以及从 1 到指定整数的和的方法。 + //在 Main 方法中分别调用定义好的方法。 + + //提示:根据题目要求,分别定义 3 个带两个参数的方法,以及一个带一个整型参数的方法, + // 四个方法名相同。 + SumUtils s = new SumUtils(); + + s.aa(1,2); + s.aa(8); + } + } +} diff --git "a/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/SumUtils.cs" "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/SumUtils.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3929558d681af04fcc2ab6ece3b984cd34567650 --- /dev/null +++ "b/\351\273\204\345\277\240\347\243\212/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/SumUtils.cs" @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp4 +{ + class SumUtils + { + public int a { get; set; } + public int b { get; set; } + public double bc { get; set; } + public double cb { get; set; } + + public string ab { get; set; } + public string ba { get; set; } + + public void aa(int a,int b) + { + Console.WriteLine("计算两个整数相加、" + (a+b)); + } + public void aa(double bc, double cb) + { + Console.WriteLine("两个小数相加" + (bc+ cb)); + } + public void aa(string ab, string ba) + { + Console.WriteLine("两个字符串相加" + (ab + ba)); + } + public void aa(int a) + { + Console.WriteLine("以及从 1 到指定整数的和的方法" + (1+a)); + } + } +}