diff --git "a/08\351\273\204\346\245\267\351\222\212/C#\347\254\224\350\256\260.md" "b/08\351\273\204\346\245\267\351\222\212/C#\347\254\224\350\256\260.md" deleted file mode 100644 index b156f919c07601a63d95997e4be6d57de02f0101..0000000000000000000000000000000000000000 --- "a/08\351\273\204\346\245\267\351\222\212/C#\347\254\224\350\256\260.md" +++ /dev/null @@ -1,465 +0,0 @@ -# C# - -### 变量 - -**整数类型:**byte(0-255),short(-32768-32767),int(-2*10^9-2*10^9【-2147483648-2147483647】),long(-9*10^18-9*10^18) - -**浮点型:**float(-3.4*10^38-3.4*10^38),double双精度类型(-5*10^~+-1.7*10^308) - -float x = 1.1F;不加后缀F,系统会默认double类型 - -double y = 1.1; - -double 可以包含:byte,short,int,long,float - -**十进制类型:**decimal(-+7.9*10^28) :decimal z = 1.1M 不是基础类型,不能和float,double相互转换 - -**布尔型:**bool - -**字符串类型:**string【string x = "Hello world" 切记加双引号 】 ,char【char x = "H" 只能一个】 - -string x = "Hello"+"world" - -x.ToString() 转换成字符串方法 - -### 值类型 - -| 类型 | 描述 | 范围 | 默认值 | -| ------- | -------------------- | --------------------------------------------------------- | ------ | -| bool | 布尔值 | True 或 False | False | -| byte | 8 位无符号整数 | 0 到 255 | 0 | -| char | 16 位 Unicode 字符 | U +0000 到 U +ffff | ‘\0’ | -| decimal | 128 位精确的十进制值 | 28-29 有效位数 (-7.9 x 1028 到 7.9 x 1028) / 10^0 到 28^0 | 0.0M | -| double | 64 位双精度浮点型 | (+/-)5.0 x 10-324 到 (+/-)1.7 x 10308 | 0.0D | -| float | 32 位单精度浮点型 | -3.4 x 1038 到 + 3.4 x 1038 | 0.0F | -| int | 32 位有符号整数类型 | -2,147,483,648 到 2,147,483,647 | 0 | -| long | 64 位有符号整数类型 | -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 | 0L | -| sbyte | 8 位有符号整数类型 | -128 到 127 | 0 | -| short | 16 位有符号整数类型 | -32,768 到 32,767 | 0 | -| uint | 32 位无符号整数类型 | 0 到 4,294,967,295 | 0 | -| ulong | 64 位无符号整数类型 | 0 到 18,446,744,073,709,551,615 | 0 | -| ushort | 16 位无符号整数类型 | 0 到 65,535 | 0 | - -sizeof() :表达式 sizeof(type) 产生以字节为单位存储对象或类型的存储尺寸。 - - - -### 算数运算符 - -【+】两数相加 - -【-】两数相减 - -【*】两数相乘 - -【/】相除取整,两数相除,结果还是整数 - -【%】取余 - -【++】自增 - -【–】自减 - - - -### 逻辑运算符 - -【&&】逻辑与,A&&B,A和B都非0,返回True,若A为0,则不对B判定,直接结果为False。 - -【||】逻辑或,A||B,A和B任意有一个非0,则结果为True。 - -【!】非,取反 - - - -### 关系运算符 - -【】AB,检查A和B是否相等 - -【!=】A!=B,检查A和B是否不等 - -【>,<,<=,>=】大于,小于,小于等于,大于等于 - - - -### 赋值运算符 - -【=】注意区分=和== - - - -### C#分支语句 - -if-else语句 - -if-else 嵌套语句 - -switch语句 - -seitch嵌套语句 - -switch()可以用数字判断,也可应用字符串判断 - -三目运算符:【x?y : z】也是一种判断 - - - -### C#循环语句 - -```c# -1、for循环 【增强for循环:foreach多用在遍历字典或者集合上】 - - - -using System; - - - -namespace test_2020 - -{ - -class Program - -{ - -static void Main(string[] args) - -{ - -/* for 循环执行 */ - -for (int a = 10; a < 20; a = a + 1) - -{ - -Console.WriteLine("a 的值: {0}", a); - -} - -Console.ReadLine(); - -} - -} - -} - -2、while循环 【先判断,再循环】 - - - -using System; - - - -namespace test_2020 - -{ - -class Program - -{ - -static void Main(string[] args) - -{ - -/* 局部变量定义 */ - -int a = 10; - - - -/* while 循环执行 */ - -while (a < 20) - -{ - -Console.WriteLine("a 的值: {0}", a); - -a++; - -} - -Console.ReadLine(); - -} - -} - -} - -3、do-while循环 【先循环一次,在判断】 - - - -using System; - - - -namespace test_2020 - -{ - -class Program - -{ - -static void Main(string[] args) - -{ - -/* 局部变量定义 */ - -int a = 10; - - - -/* do 循环执行 */ - -do - -{ - -Console.WriteLine("a 的值: {0}", a); - -a = a + 1; - -} while (a < 20); - - - -Console.ReadLine(); - -} - -} - -} - -4、break和continue - -break 直接退出循环 - -continue 退出本次循环(跳过随后一条语句) -``` - - - -### C#数组 - -```c# -初始化: - -int[] num = new int[6] //定义int数组长度为6【0 1 2 3 4 5】 - -int[] num = new int[]{1,2,3} //给定内容1,2,3 - -int[] num = new int[3]{1,2,3} //[]内是数组长度 - -int[0] = 1 //数组第一赋值为 1 索引器是从0开始 - -string str = new string[]{"Hello world"}; //标准写法new一个 - -string str = {"Hello", "world"};//简写 - -获取数组的值: - -注意索引器是从0开始的,所以要减 1 - - - -访问数组:循环遍历数组每一个值,foreach() 遍历函数 - -foreach (int j in num ) // num[] 是一个数组 - -{ - -Console.WriteLine(j); - -} -``` - -### 枚举类型 - -```c# -访问修饰符 enum 变量名 : 数据类型 -{ - 值l, - 值2, -} -``` - -# 方法 - -## (1) 方法的作用 - -简化,重用代码。使得代码可读性强。 - -## (2)定义&调用方法 - -​ 定义方法 - -```c# -访问修饰符 static 返回值类型 方法名() -public static void accu() -{ - int sum = 0; - for(int i = 1; i <= 10;i++) - { - sum += i; - } -} -``` - -​ 定义相当于做好了一个工具,等待后面使用它。 - -​ 如何调用方法? - -```c# -public static void Main(String[] args) -{ - accu(); -} -``` - -主方法必须是static的,因为这个方法不能依赖任何该类的实例即可运行,而**非static的方法,在运行之前要先创建该类的实例对象**。 - -如何定义并调用一个非静态的方法 - -```c# -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } -``` - -##(3)方法的参数传递机制 - -​ 方法在Java中只有一个值传递,但是在C#中,可以有value(值传递),ref(引用传递)和out(输出传递) - -其中,ref和out使用效果上面是等效的,它们的区别在于:参数标记为ref,那么必须在调用函数之前初始化参数的值;参数标记为out,调用函数之前不需要初始化对象,但调用的函数必要在函数返回之前为对象赋值 - -```c# -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j) - { - j++; - } - - public static void OutFun(out int k) - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - int k; - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} - -``` - -## (4)方法的重载 - -重载:方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 - -```C# -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -//1.形参个数不同: 1和2 -//2.相同个数,形参类型不同:1,3,4 -//3.形参数据类型顺序不一致 -``` - - - -### 类和对象 - -**面向对象︰**一种软件开发的思想,指导程序员如何分析、解决问题。 -**类**是一个抽象的概念,即为生活中的”类别”。 -对象是类的具体实例,即归属于某个类别的”个体”。 -例如∶学生是一个类,表示一种类型,”八戒同学”则是一个对象。 -名词类型的共性,作为数据成员。动词类型的共性,作为方法成员。 - -**一、创建类** -语法∶ -访问级别 class 类名 -{ - 类成员... -} -通常每个类都在一个独立的c#源文件中。 - -**二、创建对象** -语法: -类名 引用名; -引用名 = new 构造函数(参数列表); -创建对象的过程也称为”实例化”, - -**三、访问修饰符** -用于修饰类及类成员的访问可见范围。 -public:所属类的成员以及非所属类的成员都可以访问。 -private:只有所属类的成员才能访问。[类成员的默认级别构造函数 - -**四、构造函数** - -```c# -提供了创建对象的方式,初始化类数据成员的特殊方法。 -语法∶ -[访问修饰符] 类名( [参数列表] ) -{ - 初始化...... -} - -``` - -**特点:** - -``` -与类同名。 -没有返回值,也不能写void。 -不能被直接调用,必须通过new运算符在创建对象时才会自动调用。 -每个类都必须至少有一个构造函数,若不提供,编译器自动生成一个无参构造函数。 -如果程序员定义了构造函数,则编译器不会再提供。 -``` - -**五、this关键字** - -``` -表示当前对象的引用。 -访问当前类成员时,使用this关键字,可以提高代码的可读性; -在没有歧义的情况下,也可以省略。 -``` - diff --git "a/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260.md" "b/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260.md" deleted file mode 100644 index f3839520174ec7dd751a2e1ff9e3bd7d1052e243..0000000000000000000000000000000000000000 --- "a/10\344\275\231\351\207\221\346\230\237/\347\254\224\350\256\260.md" +++ /dev/null @@ -1,472 +0,0 @@ -//输出 - -```c# -Console.WriteLine("Hello World!");//println -Console.Write();//print -``` - -//输入 - -```c# -string a = Console.ReadLine(); -Console.WriteLine(a); -``` - -//变量 - -```c# -int a=6; -string a="abc"; -var a="abc"; -int(32位) -short(16位) -byte -``` - -//常量const 数据类型 常量名 = 值; - -```c# -const int a = 7; -``` - -//数据类型: - -```c# -byte,short,int,long,float,double,char,bool(布尔型),decimal(0,9) -``` - -//赋值运算:+=,-=,*=,/=,%= -//运算符: -//算数:+ - * / % -//比较:>,<,>=,<=,!=,== -//逻辑:&&,||,! -//三元:(条件表达式A)?A为True:A为False - -```c# -int a = 5; -int b = 8; -int c = 7; -int max = a > b ? (a>c?a:c) : (b>c?b:c); -Console.WriteLine(max); -``` - -//循环结构 四要素:1.初始值 2.判断条件 3.循环体 4.迭代因子 - -```c# -//while()循环 -int i = 1; -while (i<=10) -{ - sum = sum + i;//sum+=i; - i++; -} -Console.WriteLine(sum); -//for()循环 -int sum = 0; -for (int i = 1; i <= 10; i++ ) -{ - sum = sum + i;//sum+=i; -} -Console.WriteLine("和{0}", sum); - -``` - -//数组:初始化 - -```c# -int[] arr = new int[5];//动态 -int[] arr = new int[]{1,2,3,4,5};//静态(数组的长度和内容固定) -``` - -//命名规范 - -```c# -1.要做到 见名识义 -2.驼峰命名法 -变量,方法:小驼峰:myName, myClassName() -string myName = "蜗牛"; -大驼峰:类名,命名空间,属性:public class MyDataBase -``` - -//随机数 - -```c# -int[] arr1 = new int[5]; -Random rd = new Random(); -for (int i = 0; i < arr1.Length; i++) -{ - Arr[i] = rd.Next(0, 5); -} -foreach(var i in Arr1) -{ - Console.Write(i+" "); -} -``` - -//foreach() 只读,不能修改。 引用类型 - -```c# -foreach(var i in arr1) -{ - Console.WriteLine(i); -} -``` - -```c# -//输出数组中的最大最小值 -Random a = new Random(); -int[] ar = new int[10]; -for (int I =0;I ar[i + 1] ? ar[i + 1] : MIN; -} -Console.WriteLine(MAX+" "+MIN); - -//将一个数组中的元素逆序输出,即第一个元素和最后一个元素交换, -//第二个数与倒数第二元素交换…..,例如:原数组为:9 2 5 7 8, -//逆序后的数组为:8 7 5 2 9 -int[] arr2 = new int[5]; -for(int i = 0; i < arr2.Length; i++) -{ -arr2[i] = Convert.ToInt32(Console.ReadLine()); -} -//逆序前 -Console.WriteLine("逆序前:"); -foreach (var i in arr2) -{ - Console.WriteLine(i); -} -//逆序 -9 2 5 7 8 -8 2 5 7 9 -8 7 5 2 9 -8 7 5 2 9 -int t; -for(int i = 0; i < arr2.Length/2; i++) -{ - t = arr2[i]; - arr2[i] = arr2[arr2.Length - 1-i]; - arr2[arr2.Length - 1 - i] = t; -} -Console.WriteLine("逆序后:"); -foreach (var i in arr2) -{ - Console.WriteLine(i); -} -//bubble -int[] bub = { 8, 7, 4, 6, 5, 3 }; -//外层for控制第几趟 -for(int i = 0; i < bub.Length; i++) -{ -//每一趟找出最大往下沉 - for(int j = 0; j < bub.Length-1-i; j++) - { - if (bub[j] > bub[j + 1]) - { - int temp = bub[j]; - bub[j] = bub[j + 1]; - bub[j + 1] = temp; - } - } -} -foreach (var i in bub) -{ - Console.WriteLine(i); -} - -``` - -//枚举 - -```c# -using System; - -namespace TEST02_1 -{ - -class Program -{ - enum name - { - 第一, - 第二, - 第三 - }; - - //矩阵数组,交错数组 - static void Main(string[] args) -{ -foreach (var i in Enum.GetValues(typeof(name))) -{ - Console.WriteLine(i); -} -``` - -//二维数组 - -```c# -int[,] arr = {{1,2,3},{4,5,6},{7,8,9}}; -int[][] arr = new int[5][]; -int[,] arr2 = new int[3,3]; -for (int i = 0; i < arr.GetLength(0); i++) -{ -for (int j = 0; j < arr.GetLength(1); j++) - { - Console.WriteLine(arr[i, j]); - } -} -``` - -//方法 - -```c# -//定义方法:访问修饰符 static 返回值类型 方法名() -public static void accu() -{ - int sum = 0; - for(int i = 1; i <= 10;i++) - { - sum += i; - } -} -//调用方法 - public static void Main(String[] args) -{ - accu(); -} -//定义并调用一个非静态的方法 -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } -``` - -传递value(值传递)、ref(引用传递)、out(输出传递) - -```c# - -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j) - { - j++; - } - - public static void OutFun(out int k) - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - int k; - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} -``` - -方法的重载重载: - -```c# -//方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -``` - -```c# -class Person - { - //老贺 属性.行为(19,男,长得很帅,声音好听,大长腿 - //唱,跳,rap,篮球,玩CSGO,吹牛,看妞,学习) - public string name; - public int age; - public string gender; //性别 - public double height; // - public double weight; - public string nation; - public string hobby; - public string skin; - //行为 - - //构造方法:初始化成员变量 - public Person(string Name, int Age, string Gender, double Height, - double Weight, string Nation, string Hobby, string Skin) - { - this.hobby = Hobby; - this.name = Name; - this.age = Age; - this.gender = Gender; - this.height = Height; - this.weight = Weight; - this.nation = Nation; - this.skin = Skin; - - } - - private void walk() //私有的:private:当前类里边使用 - { - Console.WriteLine("走路"); - } - - public void eat() //公共的:所有地方都能用 - { - Console.WriteLine("{0}岁的,{3}皮的,{4}的,{5}的,在吃饭,等下要去{2}", age, name, hobby, skin, height, weight); - } - - } -//program.cs - static void Main(string[] args) - { - //面向对象(三大特性):封装,继承,多态, - //Java,C#完全面向对象,C++(泛型) - //面向过程:C语言,C++ - - //实例化 - //Person p = new Person("老贺", 19, "男", 178, 65,"中国", "看妞", "黄"); - //p.name = "老贺"; - //p.age = 19; - //p.gender = "男"; - //p.hobby = "看妞"; - //p.skin = "黄"; - //p.height = 178; - //p.weight = 65; - //p.nation = "中国"; - //p.eat(); - //Console.ReadLine(); - - Role H = new Role("林黛玉", "男", "北京", "高大上", "第一", "贾宝玉", "林某某", "贾某某"); - H.plase(); - Console.ReadLine(); - //程序 = 算法(算法导论)+数据结构(面向对象) - //11. 用户输入整数n,计算1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) - //1.n! - //2.(1!+2!+…n!) = fact(1)+fact(2)..+fact(n-1)+fact(n) - // 1 + 2+3 +4+...+n - //3.1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) - //umFact(1)+sumFact()+...+sumFact(n) - static int fact(int n) - { - int ji = 1; - for(int i = 1; i <= n; i++) - { - ji *= i; - //累乘 - } - return ji; - } - - //2.(1!+2!+…n!) = fact(1)+fact(2)..+fact(n-1)+fact(n) - //累加 - static int sumFact(int n) - { - int sum = 0; - for(int i = 1; i <= n; i++) - { - sum += fact(i); - } - return sum; - } - - //sumFact(1)+sumFact()+...+sumFact(n) - static void sumFcat1(int n) - { - int sum = 0; - for(int i = 1; i <= n; i++) - { - sum += sumFact(i); - } - } - } -``` - -```c# -//值类型:表示实际数据 接存储值 据存储在堆栈中 nt、char,结构stuct -简单类型: -有符号整型:int long short sbyte -无符号整型:uint ulong ushort usbyte -字符类型:char -浮点型:float double decimal -布尔型:bool -枚举:enum -结构体类型:struct -//引用类型:数据存储在堆中 存储数据的地址 类、数组、字符串 -类:基类:System.Object 字符串:String 自定义类:class -接口:interface -数组:int[] string[] -//值类型与引用类型的区别 - //值类型: - //1.内存分配: - //值类型总会分配到变量被声名的地方 - //声名的是局部变量,将被分配到栈上 - //声名为引用类型成员时,则被分配到托管堆上 - //2.赋值方式: - //复制变量包含的值 - //3.基类 - //值类型继承自Sysetem.ValueType-->System.ValueType又继承自System.Object - //引用类型: - //1.内存分配: - //实例总是分配到托管堆上 - //变量存储在栈中,因为变量只是实例数据的一个引用。可理解为一个地址 - //2.赋值方式: - //复制对象的引用,即对象的地址 - //3.基类 - //引用类型继承自System.Object -//存与堆内存 -栈区:存放值类型的对象本身,引用类型的引用地址(指针), -静态区对象的引用地址(指针),常量区对象的引用地址(指针)等 -堆区:用于存放引用类型对象本身 -//装箱和拆箱 -装箱:将值类型转换为引用类型 -int value =9; -Object obj =value; -拆箱:将引用类型转换为值类型 -int values=10; -Object obj =value; -int b=(int)Obj; - -``` - diff --git "a/10\344\275\231\351\207\221\346\230\237/\347\254\254\345\233\233\347\253\240\344\275\234\344\270\232.md" "b/10\344\275\231\351\207\221\346\230\237/\347\254\254\345\233\233\347\253\240\344\275\234\344\270\232.md" deleted file mode 100644 index 857fad91d9a46fd9e096c248eeaf1030e222ff30..0000000000000000000000000000000000000000 --- "a/10\344\275\231\351\207\221\346\230\237/\347\254\254\345\233\233\347\253\240\344\275\234\344\270\232.md" +++ /dev/null @@ -1,163 +0,0 @@ -```c# -//第一题 -using System; -using System.Collections.Generic; -using System.Text; - -namespace TSTS -{ - class Student - { - //创建一个Student类,类中包含三个公共成员变量:stuName(学生姓名),stuAge(学生年龄),stuSex(学生性别),一个静态成员 变量tcAge(共青团员退团年龄),定义一个构造函数用于初始化学生姓名,学生年龄,学生性别,再定义一个无参构造函数,再定 义一个静态的方法SayHello(),输出学生的所有信息,实例化一个对象Mary - public string stuName; - public int stuAge; - public char stuSex; - public static int tcAge=25; - //构造函数 - public Student(string stuname,int stuage,char stusex) - { - this.stuName = stuname; - this.stuAge = stuage; - this.stuSex = stusex; - } - public static void SayHello(string stuname, int stuage, char stusex) - { - Console.WriteLine("姓名:{0},年龄:{1},性别:{2}",stuname,stuage,stusex); - } - //无参 - public void student() - { - - } - } -} -``` - -```c# -//第二题 -using System; -using System.Collections.Generic; -using System.Text; - -namespace TSTS -{ - class Math - { - //创建一个Math类,里边定义两个静态的方法,一个用于求两个数的和,另一个用于求三个数的和,方法名都定义成Add()(利用方法的重载) - int a; - int b; - int c; - //两个数的和 - public static void add(int a,int b) - { - int sum = a + b; - Console.WriteLine("两个数的和为:{0}",sum); - } - //三个数的和 - public static void add(int a, int b, int c) - { - int sum = a + b + c; - Console.WriteLine("三个数的和为:{0}", sum); - } - } -} -``` - -```c# -//第三题 -using System; -using System.Collections.Generic; -using System.Text; - -namespace TEST -{ - class Employee - { - #region 编写一个程序,用于计算三个职员的工资。 - //第一位职员默认的基本工资为1000元 - //第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 - //第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。 - //奖金应加到基本工资内(提示:创建一个Employee类,类中创建一个ComputeSalary()的方法, - //为每个不同类别的职员重载该方法) - - //第一位职员默认的基本工资为1000元, - public void ComputeSalary(int t) - { - Console.WriteLine("第一位职员的工资{0}", t); - } - //第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 - public void ComputeSalary(int t, int a) - { - Console.WriteLine("请输入基本工资"); - t = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("请输入房租津贴"); - a = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("第二位职员的工资{0}", t + a); - } - //第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。 - public void ComputeSalary(int t, int a, int w) - { - Console.WriteLine("请输入是经理还是不是,是则有奖金收入"); - string name = Console.ReadLine(); - if (name.Equals("是")) - { - Console.WriteLine("请输入奖金"); - w = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("经理的工资{0}", t + a + w); - } - else - { - Console.WriteLine("没有奖金!基本职员"); - } - } - #endregion - } -} -``` - - - -```c# - using System; - -namespace TSTS -{ - class Program - { - static void Main(string[] args) - { - //第一题 - Student a = new Student("张三", 28, '男'); - a.student(); - Console.WriteLine("姓名:{0}年龄:{1}性别:{2}",a.stuName,a.stuAge,a.stuSex); - //第二题 - Math.add(1, 20); - Math.add(1, 3, 33); - //第三题 - Console.WriteLine("1是第一位职员、2是第二位职员、3是第三位职员"); - Console.WriteLine("请输入一个数:"); - int W = Convert.ToInt32(Console.ReadLine()); - if (W == 1) - { - Employee a = new Employee(); - a.ComputeSalary(1000); - } - else if (W == 2) - { - Employee a = new Employee(); - a.ComputeSalary(0,0); - } - else if (W == 3) - { - Employee a = new Employee(); - a.ComputeSalary(1000,500,0); - } - else - { - Console.WriteLine("输入错误,请重新输入!!!"); - } - } - } -} -``` - diff --git "a/12 \345\221\250\346\263\275\345\274\272/c#1.md" "b/12 \345\221\250\346\263\275\345\274\272/c#1.md" deleted file mode 100644 index 1335b3390ff0959f1cc2ec745f27468c67e73108..0000000000000000000000000000000000000000 --- "a/12 \345\221\250\346\263\275\345\274\272/c#1.md" +++ /dev/null @@ -1,132 +0,0 @@ -1.输出 - -``` -Console.Write(); //print -Console.WriteLine("Hello World!"); //println -``` - -2.输入 - -``` -string a = Console.ReadLine()Console.WriteLine(a); -``` - -3.变量 - -``` -int b = 6; -string c = "abc"; -var d = 5; -var e = "abc"; -int(32位) short(16位) byte -有符号,无符号 short: -32628 - 32627 ushort -``` - -4.常量 - -``` - const int e1 = 7; -``` - -5.数据类型 - -``` -byte,short,int,long,float,double,char,bool(布尔型),decimal(4,2) -``` - -``` -decimal a1 = 4.0M; -Console.WriteLine(a1); -``` - -6.运算符:算数,比较,逻辑,三元 - -``` -算数:+-*/% -赋值运算:+=,-=,*=,/=,%= -b += 1;// b= b+1, b++,++b -比较:>,<,>=,<=,!=,== -bool b1 = b >= 7; -逻辑:&&, ||, ! -三元: (条件表达式A)?A为true:A为false -int a = 5; -int b = 8; -int c = 7; -int max = a > b ? (a>c?a:c) : (b>c?b:c); -Console.WriteLine(max); -``` - -region 选择结构 -7.选择结构 - -如何输入一个整数 - -``` -int a1 = Convert.ToInt32(Console.ReadLine()); -``` - -``` -if(a1<0 || a1>100) //0-100 - //{ - // Console.WriteLine("输入错误"); - //}else if (a1 > 80) - //{ - // Console.WriteLine("A"); - //} - //else if(a1 > 60) - //{ - // Console.WriteLine("B"); - //} - //else - //{ - // Console.WriteLine("C"); -``` - -8.循环结构 -四要素:1.初始值 2.判断条件 3.循环体 4.迭代因子 - - //while (i<=10) - //{ - // sum = sum + i;//sum+=i; - // i++; - //} - //Console.WriteLine(sum); - - //for() - - //int sum = 0; - //for (int i = 1; i <= 10; i++ ) - //{ - // sum = sum + i;//sum+=i; - //} - //Console.WriteLine("和{0}", sum); - -foreach() -统计输入有多少字符,多少数字,多少特殊符号。 -AscII -统计字符 - -``` -int countChar = 0, countNumber = 0, countSym = 0; - Console.WriteLine("请输入一串字符:"); - string str = Console.ReadLine(); //fakghiag 4#&$#E - foreach (char j in str) - { - if (j >= 'A' && j <= 'Z' || j >= 'a' && j <= 'z') - { - countChar++; - } - else if (j >= '0' && j <= '9') - { - countNumber++; - } - else - { - countSym++; - } - } -``` - - - - Console.WriteLine("数字{0},字母{1},特殊符号{2}", countNumber, countChar, countSym); \ No newline at end of file diff --git "a/12 \345\221\250\346\263\275\345\274\272/c#2.md" "b/12 \345\221\250\346\263\275\345\274\272/c#2.md" deleted file mode 100644 index 4bed28d5c97f9c8d507c19adb288fceb4ee19b9a..0000000000000000000000000000000000000000 --- "a/12 \345\221\250\346\263\275\345\274\272/c#2.md" +++ /dev/null @@ -1,66 +0,0 @@ - //命名规范 - //1.要做到 见名识义 - //2.驼峰命名法 - //变量,方法:小驼峰:myName, myClassName() - string myName = "蜗牛"; - //大驼峰:类名,命名空间,属性:public class MyDataBase - -数组 - //初始化: - //静态(数组的长度和内容固定) - //int[] arr = new int[]{1,2,3,4,5}; - ////动态 - //int[] arr1 = new int[5]; - ////数组遍历 - ////随机数 - ////数组长度:arr1.Length - - -foreach() 只读,不能修改。 引用类型 - -``` -foreach(var i in arr1) -{ - Console.WriteLine(i); -} -``` - - #endregion - - - -矩阵数组,交错数组 - static void Main(string[] args) - - - -如何将某个元素的下标找出来 - -``` - foreach (var i in Enum.GetValues(typeof(student))) - { - Console.WriteLine(i); - } -``` - -二维数组 - -``` -int[,] arr = { {1,2,3},{4,5,6},{7,8,9} }; -``` - -``` -for - //for (int i = 0; i < arr.GetLength(0); i++) - //{ - // for (int j = 0; j < arr.GetLength(1); j++) - // { - // Console.WriteLine(arr[i, j]); - // } - //} -``` - - ////foreach - //foreach (var i in arr) - //{ - // Console.WriteLine(i); \ No newline at end of file diff --git "a/12 \345\221\250\346\263\275\345\274\272/c#3.md" "b/12 \345\221\250\346\263\275\345\274\272/c#3.md" deleted file mode 100644 index fc1ef1f834a9a611a2fe5269f90e7c549830f9d9..0000000000000000000000000000000000000000 --- "a/12 \345\221\250\346\263\275\345\274\272/c#3.md" +++ /dev/null @@ -1,47 +0,0 @@ -方法:简化,重用代码,使程序可读性变强. - -``` - Console.WriteLine("max is {0}", max); - Console.WriteLine("a is {0}", a); - //Scanner s = new Scanner(System.in); - //Random rd = new Random(); -``` - - Program p = new Program(); - //p.getMin(); - -访问修饰符:public(公共的),private(私有的),protected(受保护的),internal(内部的) -static: 静态的 - -返回值类型:void:无返回值, 有返回值:int,double,char,bool,string,int[]; - -``` -public static int getMax(int c, int d) //形式参数 -``` - - //Java只有值传递,C#除此之外还有ref(引用)传递,out(输出)传递 - //值传递只能返回一个,ref,out可以返回多个值 - //value:实参和形参互相独立, 只进不出 - //ref:能改变实际参数的值, 又进又出 - //out : 只出不进 - -交换 - -``` - int a = 5; -​ int c = 7; -​ swapValue(ref a,ref c); -​ Console.WriteLine($"a is{a},c is {c}"); - -​ } - -​ static void swapValue(ref int a,ref int c) -​ { -​ int t = a; -​ a = c; -​ c = t; -​ } -``` - -重载(overload)和重写(override)有什么区别 -重载:方法名一样,但是:1.形参列表个数不一致;2.形参列表类型不一致;3.形参列表顺序不一致。 \ No newline at end of file diff --git "a/15\345\220\264\346\230\216\346\235\260/c#\347\254\224\350\256\260.md" "b/15\345\220\264\346\230\216\346\235\260/c#\347\254\224\350\256\260.md" deleted file mode 100644 index f8d4ac573048ba71ebf798ee74a13d39a7ab3194..0000000000000000000000000000000000000000 --- "a/15\345\220\264\346\230\216\346\235\260/c#\347\254\224\350\256\260.md" +++ /dev/null @@ -1,895 +0,0 @@ -# 一、基础 - -## (1)输出语句 - -```c# -Console.WriteLine("cw+tab连按 = 快速创建输出语句"); -``` - -#### 1.输出写法3种 - -```c# -Console.WriteLine("人把"+a+"只大象放冰箱"); -Console.WriteLine("{0}把{1}放冰箱","人","大象"); -Console.WriteLine($"{人}把{大象}放冰箱"); -``` - -***** - -## (2)==输入语句== - -```c# -Console.ReadLine();//返回的是一个字符串类型 -//常用于控制台停留,要放在最底(输入任意按键退出) -``` - -### 1.转换数据类型 - -关键字:convert(转换) - -``` -convert.to 后面可以自己选择数据类型 -Convert.ToInt32(Console.ReadLine());//转换成int -``` - -***** - -## (3)变量 - -定义一个变量: - -数据类型 变量名 = 值; - -例如: - -``` -int a=5; string b="abc" ; var c = 5或"abc" -int a,b,c,d//连续定义 -int a;//分开定义 -a=5; -``` - -***** - -## (4)常量 - -关键字:const(常量) - -``` -加上const以后正常赋值 -const int f = 20;再次赋值将报错 -``` - -***** - -## (5)数据类型 - -#### 1.整形 - -到9顺序从小到大,有范围是比较常用 - -1. sbyte -2. byte:范围0~255 -3. short:范围-32768 ~ 32767 -4. ushort:范围0~65535 -5. int:范围-2147483648 ~ 2147483648 -6. uint:范围0 ~ 4294967295 -7. long :范围-9223372036854775808 ~ 9223372036854775808 -8. ulong -9. char -10. short:有符号,范围:-32768~32767 -11. ushort:无符号(指没负号即-),范围:0~65535 - -#### 2.浮点型 - -1. float:范围可以从1.5*10 -45~3.4* 10 38,精确到小数点后面7位 -2. double:范围可以从5.0*10 -324~1.7* 10 308,精确到小数点后面15或16位 - -#### 3.字符型:string - -#### ==4.小数类型== - -decimal:数值范围从1.0*10 -28~7.9* 10 28,精确到小数点后面28位。 - -如果希望实数被视为decimal类型,需要使用后缀M或m - -``` -decimal a1 = 4.0M; -``` - -#### 5.布尔型:bool - - 真的生成:true;假的生成:false - -***** - -## (6)运算符 - -#### 1.算数:+,-,*,/,% - -#### ==2.比较运算符== - -==,!=,<=,>=,<,>, - -#### 3.逻辑运算符: - -&&:与 ||:或 !:非 - -#### 4.三元运算符 - -(条件表达式A)?A为true:A为false - -例如:如果a>5?输出大于:否者输出小于 - -``` -Console.WriteLine("a{0}5",a>5?"大于":"小于"); -``` - -***** - -## (7)收起代码 - -代码前一行:#region 名字 代码最后一行:#endregion - -***** - -## (8)选择分支结构 - -#### 1.if语句: - -```c# -if (a >= 80)//判断条件 -{ -Console.WriteLine("优秀"); -} -else if (a >= 60) -{ -Console.WriteLine("合格"); -} -else//否则 -{ -Console.WriteLine("不及格"); -} -``` - -#### 2.swich语句 - -```c# -switch (a) -{ -case 1:Console.WriteLine("星期一"); break; -case 2: Console.WriteLine("星期二"); break; -case 3: Console.WriteLine("星期三");break; -default: Console.WriteLine("输入错误"); break; -} -``` - -***** - -## (9)循环结构 - -#### 1.while循环 - -```c# -int i=1;//初始值 -while (i <= 10)//判断条件 -{ -sum = sum + i;//循环体 -i++;//迭代 -} -Console.WriteLine(sum); -``` - -#### 2.for循环 - -```c# -int sum = 0; -for (int i = 1; i <= 100; i++)/条件初始化 条件判断 迭代 -{ -sum += i;//循环体 -} -Console.WriteLine(sum); -``` - -#### 3.foreach循环: - -不知道循环的次数时使用 - - -```c# -int[] arr1 = { 1, 2, 3, 4, 5 }; -int sum = 0; -foreach (int i in arr1)//arrl是一个变量可以换变量名 -{ -Console.WriteLine(i); -} -运行结果是把数组一个一个竖着输出 -``` - -```c# -//统计输入有多少字符,多少数字,多少特殊符号。 -//根据AscII表 -//统计字符 -int countChar = 0, countNumber = 0, countSym = 0; -Console.WriteLine("请输入一串字符:"); -string str = Console.ReadLine(); //fakghiag 4#&$#E -foreach (char j in str) -{ -if (j >= 'A' && j <= 'Z' || j >= 'a' && j <= 'z') -{ -countChar++; -} -else if (j >= '0' && j <= '9') -{ -countNumber++; -} -else -{ -countSym++; -} -} -Console.WriteLine("数字{0},字母{1},特殊符号{2}", countNumber, countChar, countSym); -``` - - - -#### ==4.可在循环过程中添加的语句== - -break语句: 在多层循环中, 一个break语句只向外跳一层。 -continue语句: 作用是跳过循环体中剩余的语句并到循环末尾而强行执行下一次循环。 - -***** - -# 二、数组 - -## (1)一维数组的声明 - -```c# - int []a=new int [2];//动态 - int[] b = {1,2,3,4 };//静态(数组的长度和内容固定) -``` - -********* - -## (2)一维数组的遍历 - -==数值的长度==:b.Length - -#### 1.第一种遍历 - -```c# -for (int i = 0; i < b.Length; i++) -{ -Console.WriteLine(b[i]); -} -``` - -#### ==2.第二种遍历foreach== - -```c# -foreach (int i in b) { Console.WriteLine(i); } -``` - -****** - -## (3)二维数组的声明 - -```c# -int [][]c=new int [4][]; -int[,] c = new int[4, 5];//动态 -int[,] d = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } } ; -``` - -***** - -## (4)二维数组的遍历 - -#### 1.第一种遍历 - -方法:==GetLebgth(几维)== - -```c# -for (int i = 0; i < arr.GetLength(0); i++) -{ -for (int j = 0; j < arr.GetLength(1); j++) -{ -Console.WriteLine(arr[i, j]); -} -} -``` - -#### 2.第二种遍历foreach - -```c# -foreach (var i in arr) -{ -Console.WriteLine(i); -} -``` - -***** - -## (5)生成随机数 - -关键字:Random,Next - -```c# -Random a = new Random(); -int[] ar = new int[10]; -for (int I =0;I bub[j + 1])//+1记得上面长度-1,不然会溢出 - {//交换过程 - int temp = bub[j]; - bub[j] = bub[j + 1]; - bub[j + 1] = temp; - } - } -} -``` - -## (7)习题 - -#### 1.逆序输出 - -4.将一个数组中的元素逆序输出,即第一个元素和最后一个元素交换, - //第二个数与倒数第二元素交换…..,例如:原数组为:9 2 5 7 8, -//逆序后的数组为:8 7 5 2 9 - -```c# - int[] arr2 = new int[5]; - for (int i = 0; i < arr2.Length; i++) - { - arr2[i] = Convert.ToInt32(Console.ReadLine()); - } - //逆序 - //9 2 5 7 8第一次运行 - //8 2 5 7 9第二次运行 - //8 7 5 2 9第三次运行 运行到这就可以了,继续运行会导致数组交换回去(除于二的原因) - //8 7 5 2 9第四次运行 - int t; - for (int i = 0; i < arr2.Length / 2; i++)//除2 - { - t = arr2[i]; - arr2[i] = arr2[arr2.Length - 1 - i]; - arr2[arr2.Length - 1 - i] = t; - } -``` - -#### 2.输出数组中的最大最小值 - -```c# - Random a = new Random(); - - int[] ar = new int[10]; - - for (int I = 0; I < ar.Length; I++) - { - ar[I] = a.Next(10); - - }//生成随机数 - int MAX = ar[0];//定义最大最小值 - int MIN = ar[0]; - for (int i = 0; i < ar.Length - 1; i++) - { - MAX = MAX < ar[i + 1] ? ar[i + 1] : MAX; -//错误代码:MAX = ar[i] < ar[i + 1] ? ar[i + 1] : ar{i};(导致是两两比较最后输出的是倒1,2的比较结果 - //三元运算符分解 - //4 2 5 48 6 4 - //if (MAX < ar[i + 1]) - //{ - // MAX = ar[i + 1]; - //} - MIN = MIN > ar[i + 1] ? ar[i + 1] : MIN; - } - - Console.WriteLine(MAX + " " + MIN); -``` - -## (8)方法的==枚举== - -关键字:==enum==(希望得到一个固定集合的值,就采用枚举)1.遍历枚举元素 - -```c# - enum student - { - 周飘, - 金星=10, - 曾鹏 - }; -//遍历 -Foreach(var i in Enum.GetValues(typeof(weekday))) -{ -Console.WriteLine(i); -} -``` - -***** - -# 三、方法 - -## (1) 方法的作用 - -简化,重用代码。使得代码可读性强。 - -## (2)定义&调用方法 - -​ 定义方法 - -```c# -访问修饰符 static 返回值类型 方法名() -public static void accu() -{ - int sum = 0; - for(int i = 1; i <= 10;i++) - { - sum += i; - } -} -``` - -​ 定义相当于做好了一个工具,等待后面使用它。 - -​ 如何调用方法? - -```c# -public static void Main(String[] args) -{ - accu(); -} -``` - -主方法必须是static的,因为这个方法不能依赖任何该类的实例即可运行,而**非static的方法,在运行之前要先创建该类的实例对象**。 - -如何定义并调用一个非静态的方法 - -```c# -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } -``` - -##(3)方法的参数传递机制 - -​ 方法在Java中只有一个值传递,但是在C#中,可以有value(值传递),ref(引用传递)和out(输出传递) - -其中,ref和out使用效果上面是等效的,它们的区别在于:参数标记为ref,那么必须在调用函数之前初始化参数的值;参数标记为out,调用函数之前不需要初始化对象,但调用的函数必要在函数返回之前为对象赋值 - -```c# -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j) - { - j++; - } - - public static void OutFun(out int k) - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - int k; - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} - -``` - -## (4)方法的重载 - -重载:方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 - -```C# -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -//1.形参个数不同: 1和2 -//2.相同个数,形参类型不同:1,3,4 -//3.形参数据类型顺序不一致 -``` - -## (5)递归 - -​ 方法自己调用自己,递归2要素:①递归出口 ②递归表达式 - -****** - -# 四、类与对像初识 - -## (1)面向对象语言三大特性 - -1. 封装(重点):把不能对外公开的数据或者功能隐藏起来 -2. 继承:类似于现实世界继承的意思 -3. 多态:一个事物(类)有多种表现形式 - -***** - -## (1.1)面向对象的概念 - -1. 面向对象:举个例子,盖一座大楼,你想到的是楼怎么盖,哪里要有珠子,哪里要有梁,哪里楼梯等等(这就是面向对象),至于柱子该怎么建,用什么建,方的圆的,等等,这就是面向过程。 - -2. 用面向对象思考问题更符合我们人的思考方式。比如:去饭店吃饭,你只要说明吃什么就可以了,有必要还了解这个菜是怎么做的,是哪里来的,怎么去种这个菜吗? - -3. 面向对象也可以说是从宏观方面思考问题,而面向过程可以说是从细节处思考问题。在面向对象中,也存在面向过程 - - -#### 1.面向过程与对象的区别 - -```c# -面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一部一部实现,使用的时候一个一个一次调用就可以了 - -面向对象是把构成问题事务分解成各个对象,建立对象的目的不是为了完成一个步骤,而是为了描叙某个事物在整个解决问题的步骤中的行为 -``` - -#### 2.深入理解对象 - -1. 对象就是我们周围的各种各样的事物。 - - 例如:衣服、杯子、宠物、朋友、电脑、汽车、电话等。 - -2. 每个对象都有一些状态(属性)。 - - 例如:衣服{颜色,长度,面料…}。 - - 猫{名字,情绪,饥饿,}。 - -3. 有些对象会作出一些行为。 - - 例如:猫{发怒,玩耍,吃食,睡觉…}。 - -4. 对象的行为会改变对象的状态。 - - 例如:玩耍 → 疲劳=True 睡觉 → 疲劳=False 吃食 → 饥饿=False - -5. 对象的状态会影响对象的行为。 - - 例如:if( 饥饿 == False) → 吃食 return failure - -****** - -## (2)面向对象的语言 - -类 - -1. 归纳共同点 -2. 具有相同数据和方法 -3. 是具有共同行为的若干个对象的统一描述体 - -对象 - -1. 类的具体事物 -2. 类中方法的执行者 -3. 使用new创建 - -****** - -## ==(3)类的语法== - -#### 1.类的语法: - -```c# - [访问修饰符] class 类名{ - - 字段;//描述对象的状态(声明变量) - - 构造函数;//初始化对象 - - 方法;//实现对象的行为 - } -``` - -#### 2.声明成员变量(字段) - -```c# - class Student - { - public string stuName; - public int stuAge; - public string stuSex; - public int tcage = 25; - } -``` - -## ==(4)构造方法与成员方法== - -#### ==(1)构造方法== - -构造方法是类中的一种特殊的方法,构造函数名与类名相同,==不返回任何值==,可初始化成员变量 - -如果没有为类编写构造方法,系统自动生成无参数的构造方法,称为模式构造方法 - -构造方法可以更简捷的为对象赋初值,为对象开辟内存空间 - -==例化对象时才能调用==,This关键字代表当前操作的对象 - - - - 对象在创建的过程中有一个过程,当new的时候,会调用构造方法,在构造方法中可以做对象初始化操作 - -构造方法与成员方法不同,它是在对象创建时自动调用 - -构造方法可以有参数,也可以无参数 - -构造方法无返回值 - -如果定义的类没有定义构造方法,对象在创建时默认使用空构造 - -***** - -#### 2.语法结构 - -```c# -[访问修饰符] <类名>()([参数列表])//构造方法名与类名相同 -{ - //构造主体 -} -``` - -#### 3.初始化成员变量 - -```c# - public Student (string stuName,int stuAge,string stuSex) - {//初始化成员变量 - this.stuName = stuName; - this.stuAge = stuAge; - this.stuSex = stuSex; - } -``` - -#### ==4.关键字this== - -this关键字代表**对象本身**。用this关键字可以在类的内部调用属性和方法,这样代码的可读性比较高,因为它明确的指出了这个属性或方法的来源。 - -#### 5.无参构造方法 - -```c# -//3、编写一个无参的构造方法,设置默认余额为1000 - public Account()//方法名要和类名一致 - { - this.balance = 1000m; - } -``` - -#### 6.有参构造方法 - -```c# - public Student (string stuName,int stuAge,string stuSex) - {//初始化成员变量 - this.stuName = stuName; - this.stuAge = stuAge; - this.stuSex = stuSex; - } -``` - -#### ==7.创建对象(实例化类)== - -语法:类名 声明名称 = new 类名 - -例如: - -```c# -Student Mary = new Student();//声明 m ,类型为Account | 调用无参结构方法 -``` - -#### ==8.有参结构实例化类调用== - -==初始化成员变量==后可以在实例化类里给如: - -```c# -Student Mary = new Student("叶小杰", 80, "男"); -``` - -***** - -#### ==(2)成员方法== - -概念:类里面定义的方法 - -语法结构: - -```c# -[访问修饰符] 返回类型 <方法名> (形式参数) - -{ - - //方法体 - -} -``` - -##### a.访问修饰符 - -```c# -//私有的:private:当前类里边使用 -//公共的:public 所有地方都能用 -``` - -#### 1.方法调用 - -实例化类之后 - -```c# -Employee e1 = new Employee(); -对象名.方法名(实际参数) -例如: -e1.ComputeSalary(1000,500); -``` - -***** - -## (5)习题 - -Program.sc - -```c# - class Program - { - static void Main(string[] args) - { - -//临时工 - Employee e = new Employee();//基本工资 - e.ComputeSalary(1000); -//第二个 - Employee e1 = new Employee(); - e1.ComputeSalary(1000,500); - //第三个职员 - Employee e2 = new Employee(); - e2.ComputeSalary(true,800,1500); - } - } -``` - -Account.sc - -```c# -internal class Account - { - //2、声明成员变量balance表示余额 - public decimal balance; - - //3、编写一个无参的构造方法,设置默认余额为1000 - public Account() - { - this.balance = 1000m; - } - //4、编写一个有参的构造方法,让客户指定余额 - public Account(decimal balance) - { - this.balance = balance; - } - //5、编写三个成员方法,分别表示存钱,取钱和查看余额 - public void examine()//查看余额 - { - Console.WriteLine("当前余额为{0}", balance); - - } - - public void save()//存钱 - { - Console.WriteLine("默认金额为{0}", balance); - Console.WriteLine("存入:"); - decimal a = Convert.ToDecimal(Console.ReadLine()); - balance += a; - Console.WriteLine("指定余额为{0}", balance); - } - - public void draw() - { - Console.WriteLine("取款金额为"); - decimal b = Convert.ToDecimal(Console.ReadLine()); - balance -= b; - Console.WriteLine("余额为{0}", balance); - } - } -``` - -***** - -## (6)总结 - -1. 类:类是一种类型,反映了一些对象共同具有的数据和行为对象是类具体的一个个体 - -2. 成员方法:成员变量表示对象的特征,成员方法表示对象的行为 - -3. 构造方法:如果类中未定义构造方法,则提供默认构造方法 - - 构造方法分配成员变量所需内存空间,初始化成员变量 - - 定义了有参构造方法后,应该添加无参构造方法 - - 命名空间,用来组织类,namespace关键字 - -***** - -# 五、类与对象深入 - -## (1)值类型与引用类型 - -![image-20220407162637247](C:\Users\wumingjie\AppData\Roaming\Typora\typora-user-images\image-20220407162637247.png) - -![image-20220407162742485](C:\Users\wumingjie\AppData\Roaming\Typora\typora-user-images\image-20220407162742485.png) - -***** - -## (2)栈内存与堆内存 - -1. 栈区:由编译器自动分配释放 ,存放值类型的对象本身,引用类型的引用地址(指针), - - 静态区对象的引用地址(指针),常量区对象的引用地址(指针)等。其操作方式类似于数据结构中的栈。 - -2. 堆区(托管堆):用于存放引用类型对象本身。在c#中由.net平台的垃圾回收机制(GC)管理。 - - 栈,堆都属于动态存储区,可以实现动态分配。 - -3. 静态区及常量区:用于存放静态类,静态成员(静态变量,静态方法),常量的对象本身。 - - 由于存在栈内的引用地址都在程序运行开始最先入栈,因此静态区和常量区内的对象的生命周期 - - 会持续到程序运行结束时,届时静态区内和常量区内对象才会被释放和回收(编译器自动释放)。 - - 所以应限制使用静态类,静态成员(静态变量,静态方法),常量,否则程序负荷高。 - - ***** - -## (3)装箱和拆箱 - - ```c# -//装箱:将值类型--》引用类型 /隐式操作 -int a = 5; //值类型 -Object obj = a; // 引用类型 -a = 6; -Console.WriteLine("obj={0}",obj); - -//拆箱:将引用类型 --》值类型 /显示操作 -int b = (int)obj; -Console.WriteLine(b); - ``` - - diff --git "a/15\345\220\264\346\230\216\346\235\260/\344\275\234\344\270\232/22-04-05\347\254\254\344\272\214\346\254\241.md" "b/15\345\220\264\346\230\216\346\235\260/\344\275\234\344\270\232/22-04-05\347\254\254\344\272\214\346\254\241.md" deleted file mode 100644 index b832e472322125a2b7add602d9c836da7fabb534..0000000000000000000000000000000000000000 --- "a/15\345\220\264\346\230\216\346\235\260/\344\275\234\344\270\232/22-04-05\347\254\254\344\272\214\346\254\241.md" +++ /dev/null @@ -1,214 +0,0 @@ -# program.cs - -```c# - class Program - { - static void Main(string[] args) - { - //Student Mary = new Student("叶小杰", 80, "男"); - //Mary.SayHello(); - - //Math m = new Math(); - //m.Add(1, 2); - //m.Add(1, 2, 3); - - //临时工 - Employee e = new Employee();//基本工资 - e.ComputeSalary(1000); -//第二个 - Employee e1 = new Employee(); - e1.ComputeSalary(1000,500); - //第三个职员 - Employee e2 = new Employee(); - e2.ComputeSalary(true,800,1500); - } - } -``` - -# student.cs - -```c# -//一、创建一个Student类,类中包含三个公共成员变量:stuName(学生姓名),stuAge(学生年龄),stuSex(学生性别),一个静态成员变量tcAge(共青团员退团年龄),定义一个构造函数用于初始化学生姓名,学生年龄,学生性别,再定义一个无参构造函数,再定义一个静态的方法SayHello(),输出学生的所有信息,实例化一个对象Mary -class Student - { - public string stuName; - public int stuAge; - public string stuSex; - public int tcage = 25; - //public static void tcAge()//共青团员退团年龄 - //{ - //} - public Student (string stuName,int stuAge,string stuSex) - { - this.stuName = stuName; - this.stuAge = stuAge; - this.stuSex = stuSex; - } - public Student () - { - } - public void SayHello() - { - Console.WriteLine("学生姓名为{0},性别为{1},年龄为{2},退出年龄{3}",stuName,stuSex,stuAge,tcage); - } - } -``` - -# math.cs - -```c# -//二、 创建一个Math类,里边定义两个静态的方法,一个用于求两个数的和,另一个用于求三个数的和,方法名都定义成Add()(利用方法的重载) - class Math - { - public int a; - public int b; - public int c; - public int sum; - public void Add(int a,int b) - { - sum = a + b; - Console.WriteLine("2位数和为{0}",sum); - } - public void Add(int a,int b,int c) - { - sum = a + b + c; - Console.WriteLine("3位数和为{0}", sum); - } - } -``` - -# employee.cs - -```c# -//三、编写一个程序,用于计算三个职员的工资。第一位职员默认的基本工资为1000元,第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金bonus值。manager奖金应加到基本工资内(提示:创建一个Employee类,类中创建一个ComputeSalary()的方法,为每个不同类别的职员重载该方法) - class Employee - { - public decimal subsidy; - - public void ComputeSalary(decimal salary) - { - Console.WriteLine("临时工基本工资为{0}",salary); - } - - public void ComputeSalary(decimal salary,decimal subsidy) - { - Console.WriteLine("普工基本工资为{0},住房补贴为{1}", salary,subsidy); - } - - public void ComputeSalary(bool manager, decimal bonus,decimal salary) - { - if (manager) - { - Console.WriteLine("经理的基本工资为{0},奖金为{1}",salary+bonus,bonus); - } - else - { - Console.WriteLine("不是经理的基本工资为{0},住房补贴为{1}",salary); - } - } - } -``` - -***** - -# 第二种方法:employee.cs - -```c# -//三、 编写一个程序,用于计算三个职员的工资。第一位职员默认的基本工资为1000元, - // 第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 - // 第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金bonus值。manager - // 奖金应加到基本工资内(提示:创建一个Employee类,类中创建一个ComputeSalary()的方法,为每个不同类别的职员重载该方法) - internal class Employee - { - public decimal salary;//工资 - public decimal subsidy;//补贴 - public decimal bonus;//奖金 - public bool isManager; //是不是经理 - public void fb() - { - this.salary = 1000m; - this.subsidy = 500m; - this.bonus = 0m; - this.isManager = true; - } - - public void lsg()//临时工 - { - - Console.WriteLine("临时工基本工资为{0}", salary); - } - - - public virtual void ptyg(decimal salary, decimal subsidy) - { - - Console.WriteLine("普通员工基本工资为{0},住房补贴为{1}", salary, subsidy); - } - - - } - - class Employee2 : Employee - { - public void jl(bool isManager, decimal salary, decimal subsidy, decimal bonus) - { - - if (isManager) - { - Console.WriteLine("经理基本工资为{0},奖金为{1}", salary + bonus, bonus); - } - else - { - ptyg(salary, subsidy); - } - } - } -``` - -# 第二种方法 program.cs - -```c# -static void Main(string[] args) - { - Console.WriteLine("输入1查看临时工工资,输入2查看普通员工工资,输入3判断是不是经理是的话显示工资和奖金"); - int x = Convert.ToInt32(Console.ReadLine()); - Employee e = new Employee(); - if (x == 1) - { - e.lsg(); - } - else if (x == 2) - { - - Console.WriteLine("输入基本工资"); - decimal salary = Convert.ToDecimal(Console.ReadLine()); - Console.WriteLine("输入住房补贴"); - decimal subsidy = Convert.ToDecimal(Console.ReadLine()); - e.ptyg(salary, subsidy); - }else if (x == 3) - { - Console.WriteLine("判断身份是否为经理,是输入true,否输入false"); - bool isManager=Convert.ToBoolean(Console.ReadLine()); - - Console.WriteLine("输入基本工资"); - decimal salary = Convert.ToDecimal(Console.ReadLine()); - - if (isManager==true) - { - Console.WriteLine("输入奖金"); - decimal bonus = Convert.ToDecimal(Console.ReadLine()); - Employee2 e2 = new Employee2(); - e2.jl(isManager, salary, 0, bonus); - } - else - { - Console.WriteLine("输入住房补贴"); - decimal subsidy = Convert.ToDecimal(Console.ReadLine()); - Employee2 e2 = new Employee2(); - e2.jl(isManager, salary, subsidy,0); - } - } - Console.ReadLine(); - } -``` - diff --git "a/15\345\220\264\346\230\216\346\235\260/\344\275\234\344\270\232/\351\235\242\345\220\221\345\257\271\350\261\241\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" "b/15\345\220\264\346\230\216\346\235\260/\344\275\234\344\270\232/\351\235\242\345\220\221\345\257\271\350\261\241\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" deleted file mode 100644 index b9cf85efdc4b17f19d81b51e2824381be5a93898..0000000000000000000000000000000000000000 --- "a/15\345\220\264\346\230\216\346\235\260/\344\275\234\344\270\232/\351\235\242\345\220\221\345\257\271\350\261\241\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" +++ /dev/null @@ -1,118 +0,0 @@ -# Program.sc - -```c# -static void Main(string[] args) -{ - //1. - //Role R = new Role("张无忌", "男","倚天屠龙记","主角","明教教主","赵敏","张翠山","殷素素"); - //R.roles(); - - Account m = new Account(); - Console.WriteLine("输入1查看余额,输入2存款,输入3查看余额"); - int a = Convert.ToInt32(Console.ReadLine()); - - if (a == 1)//查看余额 - { - m.examine(); - - } - else if (a == 2)//存款 - { - m.save(); - - } - else if (a == 3) //取款 - { - m.draw(); - - } - else - { - Console.WriteLine("输入错误请重新输入"); - - } - - Console.ReadLine(); - } -``` - -# Role.sc - -```c# -internal class Role - { - // 1、创建一个控制台应用程序,该程序名为ClassTest,在该程序中创建一个以Role为类名的、包含以下成员的一个类。 - //角色名、性别、出处、地位、门派地位、爱侣、父亲、母亲: - public string name; - public string age; - public string prov; - public string status; - public string mstatus; - public string spouse; - public string father; - public string mother; - - public Role(string name, string age, string prov, string status, string mstatus, string spouse, string father, string mother) - { - this.name = name; - this.age = age; - this.prov = prov; - this.status = status; - this.mstatus = mstatus; - this.spouse = spouse; - this.father = father; - this.mother = mother; - } - public void roles() - { -Console.WriteLine($"他是{name},性别{age},出自{prov},教派是{status},地位是{mstatus},爱人是{spouse},父亲是{father},母亲是{mother}"); - } -} -``` - -# Account.sc - -```c# -internal class Account - { - //2、声明成员变量balance表示余额 - public decimal balance; - - //3、编写一个无参的构造方法,设置默认余额为1000 - public Account() - { - this.balance = 1000m; - } - //4、编写一个有参的构造方法,让客户指定余额 - public Account(decimal balance) - { - this.balance = balance; - } - //5、编写三个成员方法,分别表示存钱,取钱和查看余额 - public decimal examine()//查看余额 - { - Console.WriteLine("当前余额为{0}", balance); - return balance; - } - - public decimal save()//存钱 - { - Console.WriteLine("默认金额为{0}", balance); - Console.WriteLine("存入:"); - decimal a = Convert.ToDecimal(Console.ReadLine()); - balance += a; - Console.WriteLine("指定余额为{0}", balance); - return balance; - } - - public decimal draw() - { - Console.WriteLine("取款金额为"); - decimal b = Convert.ToDecimal(Console.ReadLine()); - balance -= b; - Console.WriteLine("余额为{0}", balance); - return balance; - } - } -``` - diff --git "a/18\346\235\250\346\231\250\345\223\262/\344\275\234\344\270\2321.md" "b/18\346\235\250\346\231\250\345\223\262/\344\275\234\344\270\2321.md" deleted file mode 100644 index ed54c539689e335b9a00bd0276250da7813c55d2..0000000000000000000000000000000000000000 --- "a/18\346\235\250\346\231\250\345\223\262/\344\275\234\344\270\2321.md" +++ /dev/null @@ -1,44 +0,0 @@ -using System; - -namespace ClassTest -{ - class Program - { - private Role h = new Role("޼", "", "", "", "̽", "", "Ŵɽ", ""); - h.Role; - - } -} - - -using System; -using System.Collections.Generic; -using System.Text; - -namespace ClassTest -{ - class Role - { - public string name; - public string gander; - public string provenance; - public string status; - public string ustatus; - public string lover; - public string father; - public string mother; - - public Role(string Name, string Gander, string Provenance, string Status, string Ustatus, string Lover, string Father, string Mother) - { - this.name = Name; - this.gander = Gander; - this.provenance = Provenance; - this.status = Status; - this.ustatus = Ustatus; - this.lover = Lover; - this.father = Father; - this.mother = Mother; - } - } - -} diff --git "a/24 \351\231\210\351\222\260\351\224\213c#/.keep" "b/24 \351\231\210\351\222\260\351\224\213c#/.keep" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/24 \351\231\210\351\222\260\351\224\213c#/4.1 Program.cs" "b/24 \351\231\210\351\222\260\351\224\213c#/4.1 Program.cs" deleted file mode 100644 index c4b72433e496fe684f385c88ab33c013e255957a..0000000000000000000000000000000000000000 --- "a/24 \351\231\210\351\222\260\351\224\213c#/4.1 Program.cs" +++ /dev/null @@ -1,57 +0,0 @@ -using System; - -namespace ConsoleApp1 -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - int a; - a=int.Parse(Console.ReadLine()); - Console.WriteLine("请输入a"); - //int b = 1; - int sum = jcSum(a); - - - //for (int i = 1; i <= a; i++) - //{ - - // b = b * i; - // sum = b + sum; - - //} - Console.WriteLine("a的阶乘的和是:" + sum); - static int jc(int n) - { - int jc = 1; - for (int i = 1; i <= n; i++) - { - jc = jc * i; - - } - - return jc; - } - static int jc1(int n) - { - int jc1 = 0; - for (int i = 1; i <= n; i++) - { - jc1 = jc1 + jc(i); - } - return jc1; - } - static int jcSum(int n) - { - int sum = 0; - for (int i = 1; i <= n; i++) - { - // i = 1 sum += jc(1) i = 2 sum += jc(2) i = 3 sum += jc(3) - sum += jc1(i); - } - return sum; - } - } - } -} diff --git "a/24 \351\231\210\351\222\260\351\224\213c#/4.4 \344\275\234\344\270\232 \351\231\210\351\222\260\351\224\213.txt" "b/24 \351\231\210\351\222\260\351\224\213c#/4.4 \344\275\234\344\270\232 \351\231\210\351\222\260\351\224\213.txt" deleted file mode 100644 index d6169c7260f9359de047030cce8b94b70d22e699..0000000000000000000000000000000000000000 --- "a/24 \351\231\210\351\222\260\351\224\213c#/4.4 \344\275\234\344\270\232 \351\231\210\351\222\260\351\224\213.txt" +++ /dev/null @@ -1,141 +0,0 @@ -using System; - -namespace _4._4 -{ - class Program - { - static void Main(string[] args) - { - Role H = new Role("张无忌", "男", "倚天屠龙记", "主角", "明教教主", "赵敏", "张翠山", "殷素素"); - H.plase(); - Console.ReadLine(); - Console.WriteLine("Hello World!"); - - - //作业二: - //用于模拟银行账户(Account类),要求有初始化余额(balance),存取现金操作和查看余额的操作 - //初始化余额有两种方式,默认余额(1000)和客户指定余额 - //提示: - //1、定义一个Account类 - //2、声明成员变量balance表示余额 - //3、编写一个无参的构造方法,设置默认余额为1000 - //4、编写一个有参的构造方法,让客户指定余额 - //5、编写三个成员方法,分别表示存钱,取钱和查看余额 - Account a = new Account(1000); - Console.WriteLine("默认 客户指定余额"); - string s22 = Console.ReadLine(); - if - (s22 == "客户指定余额") - { - a.a1(); - } - - - for (; ; ) - { - Console.WriteLine("存钱" + " " + "取钱" + " " + "查看余额"); - string s = Console.ReadLine(); - if (s == "查看余额") - { - a.a4(); - } - else if (s == "存钱") - { - a.a2(); - } - else if (s == "取钱") - { - a.a3(); - } - } - } - } -} - - -using System; -using System.Collections.Generic; -using System.Text; - -namespace _4._4 -{ - class Role - {//1、创建一个控制台应用程序,该程序名为ClassTest, - //在该程序中创建一个以Role为类名的、包含以下成员的一个类。 - //角色名、性别、出处、地位、门派地位、爱侣、父亲、母亲: - public string roleName; - public string gender; - public string provenance; - public string status; - public string fstatus; - public string lovepartner; - public string father; - public string mother; - //2、在ClassTest程序中,在Role类中定义一个该类的构造函数, - //实现给该类的字段赋值的功能。 - public Role(string RoleName, string Gender, string Provenance, - string Status, string Fstatus, string Lovepartner, string Father, string Mother) - { - this.roleName = RoleName; - this.gender = Gender; - this.provenance = Provenance; - this.status = Status; - this.fstatus = Fstatus; - this.lovepartner = Lovepartner; - this.father = Father; - this.mother = Mother; - } - - //3、在ClassTest程序主函数中创建一个对象,并完成给该对象的成员赋以下的值并完成输出:张无忌、男、倚天屠龙记、主角、明教教主、赵敏、张翠山、殷素素 - public void plase() - { - Console.WriteLine("{0},{1}的,来自{2},是{3},是{4},爱侣是{5},父亲是{6},母亲是{7}", roleName, gender, provenance, status, fstatus, lovepartner, father, mother); - } - - } -} - -using System; -using System.Collections.Generic; -using System.Text; - -namespace _4._4 -{ - class Account - { - public double balance; - - public Account(double Balance) - { - this.balance = Balance; - } - public void a1() - { - this.balance = Convert.ToDouble(Console.ReadLine()); - Console.WriteLine("余额为" + balance); - } - public void a2() - { - double d = Convert.ToDouble(Console.ReadLine()); - this.balance += d; - Console.WriteLine("存入的钱为" + d + "余额为" + balance); - - } - public void a3() - { - double d1 = Convert.ToDouble(Console.ReadLine()); - this.balance -= d1; - Console.WriteLine("取出的钱为" + d1 + "余额为" + balance); - } - public void a4() - { - Console.WriteLine("余额为" + balance); - } - - - } - - } - - - diff --git "a/24 \351\231\210\351\222\260\351\224\213c#/4.4\347\254\224\350\256\260.md.txt" "b/24 \351\231\210\351\222\260\351\224\213c#/4.4\347\254\224\350\256\260.md.txt" deleted file mode 100644 index 2a3ecfe383c98a3fd48c34d413813aa82040a3e8..0000000000000000000000000000000000000000 --- "a/24 \351\231\210\351\222\260\351\224\213c#/4.4\347\254\224\350\256\260.md.txt" +++ /dev/null @@ -1,96 +0,0 @@ -[访问修饰符] 返回类型 <方法名> (参数列表) -{ - //方法体 -} - - -进行命名锁定之后才可输出 -//面向对象(三大特性):封装,继承,多态, - //Java,C#完全面向对象,C++(泛型) - //面向过程:C语言,C++ - //戴口罩--》出门--》下楼梯--》走路--》点菜--》付款--》脱口罩--》吃饭 - //面向对象:我要吃饭--》吃饭 - - - //类,万物皆对象 - //类:分类:人类(男人,女人,学生,歌手,演员),吉他,鸟类,肉类,海鲜类 - //对象:贺晋卓,黄楷钊, 愤怒的小鸟,燕子,麻雀, 鱼,虾(皮皮虾,濑尿虾,小龙虾,大龙虾) - - //实例化 - //Person p = new Person("老贺", 19, "男", 178, 65,"中国", "看妞", "黄"); - //p.name = "老贺"; - //p.age = 19; - //p.gender = "男"; - //p.hobby = "看妞"; - //p.skin = "黄"; - //p.height = 178; - //p.weight = 65; - //p.nation = "中国"; - //p.eat(); - //Console.ReadLine(); - - Role H = new Role("林黛玉", "男", "北京", "高大上", "第一", "贾宝玉", "林某某", "贾某某"); - H.plase(); - Console.ReadLine(); - //程序 = 算法(算法导论)+数据结构(面向对象) - - } -位于主方法,设定格式内容 - - - public string name; - public int age; - public string gender; //性别 - public double height; // - public double weight; - public string nation; - public string hobby; - public string skin; - //行为 - - //构造方法:初始化成员变量 - public Person(string Name, int Age, string Gender, double Height, - double Weight, string Nation, string Hobby, string Skin) - { - this.hobby = Hobby; - this.name = Name; - this.age = Age; - this.gender = Gender; - this.height = Height; - this.weight = Weight; - this.nation = Nation; - this.skin = Skin; - - } - - - private void walk() //私有的:private:当前类里边使用 - { - Console.WriteLine("走路"); - } - - public void eat() //公共的:所有地方都能用 - { - Console.WriteLine("{0}岁的,{3}皮的,{4}的,{5}的,在吃饭,等下要去{2}", age, name, hobby, skin, height, weight); - } -语法结构 - -如果没有为类编写构造方法,系统自动生成无参数的构造方法,称为模式构造方法 -无参构造方法 -有参构造方法 - - -构造方法可以更简捷的为对象赋初值 -为对象开辟内存空间 -例化对象时才能调用 -This关键字 -当前操作的对象 - - -构造方法 -如果类中未定义构造方法,则提供默认构造方法 -构造方法分配成员变量所需内存空间,初始化成员变量 -定义了有参构造方法后,应该添加无参构造方法 -命名空间 -用来组织类 -namespace关键字 diff --git "a/24 \351\231\210\351\222\260\351\224\213c#/c#\346\236\232\344\270\276\344\270\216\345\276\252\347\216\257.md.md" "b/24 \351\231\210\351\222\260\351\224\213c#/c#\346\236\232\344\270\276\344\270\216\345\276\252\347\216\257.md.md" deleted file mode 100644 index ade1d1e4a91cf8c078bfeabebe1e88b6ec6ff1f5..0000000000000000000000000000000000000000 --- "a/24 \351\231\210\351\222\260\351\224\213c#/c#\346\236\232\344\270\276\344\270\216\345\276\252\347\216\257.md.md" +++ /dev/null @@ -1,108 +0,0 @@ -ɣ52ĸ(A-Z, a-z)10(0-9)»(_) -ͷĸ» -ǹؼ - - -Сշ-׸ʵĸСд൥ʵĸд - int myAge = 5; static void myClassInfo( ) ڱ - -շ-еĸд: - public class DataBaseUser ԣռ - -c# -switch (int / char / stringʽ) -{ - case ʽ1: - 1; - break; // - case ʽ2: - 2; - break; // - - default: - n; - break; // -} - -c#תϢΪɹõͬ -c#飬int[ ] arr1 - - -c#ѭ -.LengthΪѭ -// ѭӡԪ -int[ ] array = new int[5] { 0, 1 ,2, 3, 4}; // ʼһά -for (int i = 0; i < array.Length;i++ ) // еԪ -{ - Console.WriteLine(array[i]); -} - - -varʽͣݾ - -C#1.02.0бָͣ -3.0Բȷָͣ -ʹvarؼ֣ʵгʼʽ㡣 - -Var number=2009 -var strs=new string[ ]{200820098020} -var ui= new UserInfo -==>> int number=2009 -string [ ]strs=new string[ ]{200820098020} -userinfo ui= new UserInfo - -ʹã -һΧֲʱʹãforУforeachУusingУ -ڶԭ򣺱һʼıʼֵΪnull -ͬһʼʽͱ - - -ö٣ͬΣȸϢö - -2) .(ά) - //飬 - static void Main(string[] args) - { - //νijԪص±ҳ - foreach (var i in Enum.GetValues(typeof(student))) - { - Console.WriteLine(i); - } - - //ά - int[,] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; - - //for - for (int i = 0; i < arr.GetLength(0); i++) - { - for (int j = 0; j < arr.GetLength(1); j++) - { - Console.WriteLine(arr[i, j]); - } - } - - //foreach - foreach (var i in arr) - { - Console.WriteLine(i); - } - - ﷨ - foreach ( Ԫ() in ϻ) - { - // - } - - - - - - - - - - - - - - diff --git "a/24 \351\231\210\351\222\260\351\224\213c#/c#\347\254\224\350\256\260\345\237\272\347\241\200\345\256\232\344\271\211.md.txt" "b/24 \351\231\210\351\222\260\351\224\213c#/c#\347\254\224\350\256\260\345\237\272\347\241\200\345\256\232\344\271\211.md.txt" deleted file mode 100644 index a0b60e47f4a86af3d6c44fdc62df198603ae9212..0000000000000000000000000000000000000000 --- "a/24 \351\231\210\351\222\260\351\224\213c#/c#\347\254\224\350\256\260\345\237\272\347\241\200\345\256\232\344\271\211.md.txt" +++ /dev/null @@ -1,184 +0,0 @@ -using System; - -namespace TEST01 -{ - class Program - { - static void Main(string[] args) - { - 1. - Console.Write(); //print - Console.WriteLine("Hello World!"); //println - - 2. - string a = Console.ReadLine(); - Console.WriteLine(a); - - 3. - int b = 6; - string c = "abc"; - var d = 5; - var e = "abc"; - int(32λ) short(16λ) byte - зţ޷ short: -32628 - 32627 ushort - - 4. - const int e1 = 7; - - - 5. - byte,short,int,long,float,double,char,bool(),decimal(4, 2) - - decimal a1 = 4.0M; - Console.WriteLine(a1); - - 6.Ƚϣ߼Ԫ - +-*/% - ֵ㣺+=,-=,*=,/=,%= - b += 1;// b= b+1, b++,++b - Ƚϣ>,<,>=,<=,!=,== - bool b1 = b >= 7; - ߼&&, ||, ! - Ԫ (ʽA) ? AΪtrue : AΪfalse - int a = 5; - int b = 8; - int c = 7; - int max = a > b ? (a > c ? a : c) : (b > c ? b : c); - Console.WriteLine(max); - - #region ѡṹ - 7.ѡṹ - A,B,Cȼѧĵijɼ, 60c, 80B,100 - aȼ, ôʵָù, жijλͬѧķȼ, ͬѧĵķ - û,ӿ̨ݾԼ - - һ - int a1 = Convert.ToInt32(Console.ReadLine()); - if (a1 < 0 || a1 > 100) //0-100 - { - Console.WriteLine(""); - } - else if (a1 > 80) - { - Console.WriteLine("A"); - } - else if (a1 > 60) - { - Console.WriteLine("B"); - } - else - { - Console.WriteLine("C"); - } - - - С - int b1 = Convert.ToInt32(Console.ReadLine()); - int b2 = Convert.ToInt32(Console.ReadLine()); - int b3 = Convert.ToInt32(Console.ReadLine()); - int b4; - if (b1 > b2) - { - b4 = b1; - b1 = b2; - b2 = b4; - - } - //b1 b3) - { - b4 = b1; - b1 = b3; - b3 = b4; - } - //b1С - if (b2 > b3) - { - b4 = b2; - b2 = b3; - b3 = b4; - } - - Console.WriteLine("{0}<{1}<{2}", b1, b2, b3); - - if (b1 > b2) - { - if (b1 > b3) - { - //b1 - if (b2 > b3) - { - //b2֮ - Console.WriteLine("{0}<{1}<{2}", b3, b2, b1); - //Console.WriteLine($"{b3}<{b2}<{b1}"); - } - else - { - //b3֮ - Console.WriteLine("{0}<{1}<{2}", b2, b3, b1); - } - } - else - { - //b3 - } - } - else - { - } - #endregion - ɽ۵ - - - 8.ѭṹ - Ҫ: 1.ʼֵ 2.ж 3.ѭ 4. - 1 +.+10 - int i = 1; - - while (i <= 10) - { - sum = sum + i;//sum+=i; - i++; - } - Console.WriteLine(sum); - - for () - - int sum = 0; - for (int i = 1; i <= 10; i++) - { - sum = sum + i;//sum+=i; - } - Console.WriteLine("{0}", sum); - - foreach () - ͳжַ֣š - AscII - ͳַ - int countChar = 0, countNumber = 0, countSym = 0; - Console.WriteLine("һַ"); - string str = Console.ReadLine(); //fakghiag 4#&$#E - foreach (char j in str) - { - if (j >= 'A' && j <= 'Z' || j >= 'a' && j <= 'z') - { - countChar++; - } - else if (j >= '0' && j <= '9') - { - countNumber++; - } - else - { - countSym++; - } - } - - Console.WriteLine("{0},ĸ{1},{2}", countNumber, countChar, countSym); - - - } - } -} \ No newline at end of file diff --git "a/30\345\220\264\350\266\205/4.5.md" "b/30\345\220\264\350\266\205/4.5.md" deleted file mode 100644 index 2fa6a1947536a1ab47aa5660299dfaa1096e150a..0000000000000000000000000000000000000000 --- "a/30\345\220\264\350\266\205/4.5.md" +++ /dev/null @@ -1,33 +0,0 @@ -类与对象深入 -(1)值类型和引用类型 - -``` -值类型数据和引用类型数据作为方法的参数时之间的差异: -``` - -(2)栈内存与堆内存 -栈区: - -``` -由编译器自动分配释放 ,存放值类型的对象本身,引用类型的引用地址(指针), 静态区对象的引用地址(指针),常量区对象的引用地址(指针)等。其操作方式类似于数据结构中的栈。 -``` - -堆区(托管堆): - -``` -用于存放引用类型对象本身。在c#中由.net平台的垃圾回收机制(GC)管理。 栈,堆都属于动态存储区,可以实现动态分配。 -``` - - - -``` -静态区及常量区:用于存放静态类,静态成员(静态变量,静态方法),常量的对象本身。 由于存在栈内的引用地址都在程序运行开始最先入栈,因此静态区和常量区内的对象的生命周期 会持续到程序运行结束时,届时静态区内和常量区内对象才会被释放和回收(编译器自动释放)。 所以应限制使用静态类,静态成员(静态变量,静态方法),常量,否则程序负荷高。 -``` - -(3)装箱与拆箱 - -``` -装箱: 将值类型装换为引用类型 隐式操作 int value = 9; Object obj = value; -拆箱: 将引用类型转换为值类型 显示操作 int value = 10; Object obj1 = value; int b = (int)obj1; -``` - diff --git "a/30\345\220\264\350\266\205/4.5\344\275\234\344\270\232.md" "b/30\345\220\264\350\266\205/4.5\344\275\234\344\270\232.md" deleted file mode 100644 index 9aded47e7baf9ba1028e7830f1fd26cb962b0dcb..0000000000000000000000000000000000000000 --- "a/30\345\220\264\350\266\205/4.5\344\275\234\344\270\232.md" +++ /dev/null @@ -1,124 +0,0 @@ -``` -using System; -using System.Collections.Generic; -using System.Text; - -namespace day5 -{ - class Math - { - // 创建一个Math类,里边定义两个静态的方法,一个用于求两个数的和, - //另一个用于求三个数的和,方法名都定义成Add()(利用方法的重载) - public int a; - public int b; - public int c; - public Math(int a, int b, int c) - { - this.a = a; - this.b = b; - this.c = c; - } - public void add(int a,int b) - { - int sum; - sum = a + b; - Console.WriteLine("和{0}", sum); - } - public void add(int a, int b,int c) - { - int sum; - sum = a + b+c; - Console.WriteLine("和为{0}", sum); - } - - - } - -} -``` - -``` -using System; - -namespace day5 -{ - class Program - { - static void Main(string[] args) - { - //Student b = new Student("张某", 20, "女"); - //b.SayHello("张某", 20, "女"); - - - //Math c = new Math(3,24,36); - //c.add(3, 24); - //c.add(3, 24, 36); - - } - } - -} -``` - -``` -using System; -using System.Collections.Generic; -using System.Text; - -namespace day5 -{ - class Student - { -// 一, 创建一个Student类,类中包含三个公共成员变量:stuName(学生姓名),stuAge(学生年龄),stuSex(学生性别), -// 一个静态成员变量tcAge(共青团员退团年龄),定义一个构造函数用于初始化学生姓名,学生年龄,学生性别, -// 再定义一个无参构造函数,再定义一个静态的方法SayHello(),输出学生的所有信息,实例化一个对象Mary - - public string stuName; - public int stuAge; - public string stuSex; - public static int tcAge; - public Student(string stuName, int stuAge, string stuSex) { - this.stuName = stuName; - this.stuAge = stuAge; - this.stuSex = stuSex; - } - public Student() { - - } - public void SayHello(string stuName, int stuAge, string stuSex) - { - Console.WriteLine("姓名{0},年龄{1},性别{2}", stuName, stuAge, stuSex); - } - - -​ - - } - -} -``` - -``` -using System; -using System.Collections.Generic; -using System.Text; - -namespace day5 -{ - class Employee - { -// 编写一个程序,用于计算三个职员的工资。 -// 第一位职员默认的基本工资为1000元, -// 第二位职员除具有基本工资外,还具有住房津贴。 -// 接受用户输入的基本工资和住房津贴。第三位职员可能是经理也可能不是, -// 如果是,则有奖金收入,应接受输入的奖金值。 -// 奖金应加到基本工资内(提示:创建一个Employee类, -// 类中创建一个ComputeSalary()的方法, -// 为每个不同类别的职员重载该方法) - - - } - -} -``` - diff --git "a/30\345\220\264\350\266\205/\347\254\224\350\256\260.md" "b/30\345\220\264\350\266\205/\347\254\224\350\256\260.md" deleted file mode 100644 index 21be7a5e50d3d79fb752084df92e1cfde285ca12..0000000000000000000000000000000000000000 --- "a/30\345\220\264\350\266\205/\347\254\224\350\256\260.md" +++ /dev/null @@ -1,304 +0,0 @@ -变量命名规则: 组成:52个字母(A-Z, a-z),10个数字(0-9),下划线(_) 开头:字母或下划线 不能是关键字 - -``` -(C# 变量命名编码规范——Camel 命名法: - 小驼峰-首个单词的首字母小写,其余单词的首字母大写: - 例如 int myAge = 5; static void myClassInfo( ) 常用于变量,方法 - 大驼峰-所有单词首字母大写: - 例如: public class DataBaseUser 常用于类名,属性,命名空间) -``` - - 字符串和数值型的互相转换 string myString = "Hello"; int myInt = int.Parse(myString); - -``` - double score = 92.6; - string myString = score.ToString( ); - - double score = 59.3; - int myInt = Convert.ToInt32 (score); -``` - -数据类型: - -``` -byte,short,int,long,float,double,char,bool(布尔型),decimal(0,9) -``` - -循环结构 四要素:1.初始值 2.判断条件 3.循环体 4.迭代因子 - -``` -//while()循环 -int i = 1; -while (i<=10) -{ - sum = sum + i;//sum+=i; - i++; -} -Console.WriteLine(sum); -//for()循环 -int sum = 0; -for (int i = 1; i <= 10; i++ ) -{ - sum = sum + i;//sum+=i; -} -Console.WriteLine("和{0}", sum); -``` - -随机数 - -``` -int[] arr1 = new int[5]; -Random rd = new Random(); -for (int i = 0; i < arr1.Length; i++) -{ - Arr[i] = rd.Next(0, 5); -} -foreach(var i in Arr1) -{ - Console.Write(i+" "); -} -``` - -C#数组 设置初始化大小: int [ ] arr = new int[5]{0,1,2,3,4,}; -int [ ] arr = new int [ ]{0,1,2,3,4,}; (省略长度) int [ ] arr = {0,1,2,3,4,}; (省略new) - -枚举 用于定义具有一组特定值的数据类型 枚举以enum关键字声明 enum student { 学生姓名 } - -foreach() 只读,不能修改。 引用类型 - -``` -foreach(var i in arr1) -{ - Console.WriteLine(i); -} -``` - -数组长度 数组名:length --------常作为循环条件 int[ ] array = new int[5] { 0, 1 ,2, 3, 4}; -for (int i = 0; i < array.Length;i++ ) -{ Console.WriteLine(array[i]); } - -二维数组 - -``` -int[,] arr = {{1,2,3},{4,5,6},{7,8,9}}; -for (int i = 0; i < arr.GetLength(0); i++) -{ -for (int j = 0; j < arr.GetLength(1); j++) - { - Console.WriteLine(arr[i, j]); - } -} -``` - -调用非静态 - -``` -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } -``` - -### 传递 - -Java只有值传递,C#除此之外还有ref(引用)传递,out(输出)传递 - -值传递只能返回一个,ref,out可以返回多个值 - -value:实参和形参互相独立, 只进不出 - -ref:能改变实际参数的值, 又进又出 - -out : 只出不进 - -``` -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j) - { - j++; - } - - public static void OutFun(out int k) - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - int k; - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} -``` - -### 重载和重写 - -1. 区别 - - 重载(overload)和重写(override)有什么区别 重载:方法名一样,但是:1.形参列表个数不一致;2.形参列表类型不一致;3.形参列表顺序不一致。 - -``` -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -//1.形参个数不同: 1和2 -//2.相同个数,形参类型不同:1,3,4 -//3.形参数据类型顺序不一致 -``` - -### 递归 - - 方法自己调用自己,递归2要素:①递归出口 ②递归表达式 - -## 面向对象 - - 面向对象(三大特性):封装,继承,多态, Java,C#完全面向对象,C++(泛型) 面向过程:C语言,C++ 戴口罩--》出门--》下楼梯--》走路--》点菜--》付款--》脱口罩--》吃饭 - - 面向对象:我要吃饭--》吃饭 - - 类,万物皆对象 类:分类:人类(男人,女人,学生,歌手,演员),吉他,鸟类,肉类,海 鲜类 - - 对象:贺晋卓,黄楷钊, 愤怒的小鸟,燕子,麻雀, 鱼,虾(皮皮虾, 濑尿虾,小龙虾,大龙虾) - -### 类与对象的使用 - -类的语法: - -``` -[访问修饰符] class 类名{ - - 字段;//描述对象的状态(声明变量) - - 方法;//实现对象的行为 - - 构造函数;//初始化对象 - - } -``` - -1. 实例化类 -2. 产生对象 -3. 使用对象 - -### 成员方法和构造方法 - -成员方法 - - 概念:类里面定义的方法 - - 语法结构: - -``` -[访问修饰符] 返回类型 <方法名> (参数列表) - -{ - - //方法体 - -} -``` - - 成员变量 - - 方法调用 - -1. 构造方法 - - 是类中的一种特殊的方法,构造函数名与类名相同,不返回任何值,可初始化成员变量 - - 语法结构 - - ``` - class Role - { - // 1、创建一个控制台应用程序,该程序名为ClassTest, - //在该程序中创建一个以Role为类名的、包含以下成员的一个类。 - //角色名、性别、出处、地位、门派地位、爱侣、父亲、母亲: - public string roleName; - public string gender; - public string provenance; - public string status; - public string fstatus; - public string lovepartner; - public string father; - public string mother; - - public Role(string RoleName, string Gender, string Provenance, - string Status, string Fstatus, string Lovepartner, string Father, string Mother) - { - this.roleName = RoleName; - this.gender = Gender; - this.provenance = Provenance; - this.status = Status; - this.fstatus = Fstatus; - this.lovepartner = Lovepartner; - this.father = Father; - this.mother = Mother; - } - public void plase() - { - Console.WriteLine("{0},{1}的,来自{2},很{3},是{4},爱侣是{5},父亲是{5},母亲是{6}", roleName, gender, provenance, status, fstatus, lovepartner, father,mother) ; - } - - } - ``` - - ``` - Role H = new Role("林黛玉", "男", "北京", "高大上", "第一", "贾宝玉", "林某某", "贾某某"); - H.plase(); - Console.ReadLine(); - ``` - -2. 如果没有为类编写构造方法,系统自动生成无参数的构造方法,称为模式构造方法 - - ``` - a.无参构造方法 - - b.有参构造方法 - - 构造方法可以更简捷的为对象赋初值,为对象开辟内存空间 - - 例化对象时才能调用,This关键字,当前操作的对象 - - 对象在创建的过程中有一个过程,当new的时候,会调用构造方法,在构造方法中可以做对象初始化操作 - - 构造方法与成员方法不同,它是在对象创建时自动调用 - - 构造方法可以有参数,也可以无参数 - - 构造方法无返回值 - - 构造方法名与类名相同 - - 如果定义的类没有定义构造方法,对象在创建时默认使用空构造 - ``` - - \ No newline at end of file diff --git "a/33\350\260\267\345\205\206\346\230\216/\344\275\234\344\270\232.md.url" "b/33\350\260\267\345\205\206\346\230\216/\344\275\234\344\270\232.md.url" deleted file mode 100644 index c447b5a20be7ab43299ef72aeb61d1fd0b52ae86..0000000000000000000000000000000000000000 --- "a/33\350\260\267\345\205\206\346\230\216/\344\275\234\344\270\232.md.url" +++ /dev/null @@ -1,2 +0,0 @@ -[InternetShortcut] -URL=https://gitee.com/gu-zhaoming/c-sharp-object-oriented-notes/blob/master/%E4%BD%9C%E4%B8%9A.md diff --git "a/33\350\260\267\345\205\206\346\230\216/\347\254\224\350\256\260.md.url" "b/33\350\260\267\345\205\206\346\230\216/\347\254\224\350\256\260.md.url" deleted file mode 100644 index 1e5bb9d9451245ad15f940a04228d4e7c0783096..0000000000000000000000000000000000000000 --- "a/33\350\260\267\345\205\206\346\230\216/\347\254\224\350\256\260.md.url" +++ /dev/null @@ -1,2 +0,0 @@ -[InternetShortcut] -URL=https://gitee.com/gu-zhaoming/c-sharp-object-oriented-notes/blob/master/%E7%AC%94%E8%AE%B0.md diff --git "a/38\345\274\240\351\235\231/c#\347\254\224\350\256\260.md" "b/38\345\274\240\351\235\231/c#\347\254\224\350\256\260.md" deleted file mode 100644 index 20574fd2911732ea913b15dc0d68dee1ae594013..0000000000000000000000000000000000000000 --- "a/38\345\274\240\351\235\231/c#\347\254\224\350\256\260.md" +++ /dev/null @@ -1,95 +0,0 @@ -# ʼǣ - -#### һ淶 - -? -? ɣ52ĸ(A-Z, a-z)10(0-9)»(_) -? ͷĸ» -? ǹؼ - - C# 淶Camel - Сշ-׸ʵĸСд൥ʵĸд - int myAge = 5; static void myClassInfo( ) ڱ - շ-еĸд - 磺 public class DataBaseUser ԣռ䣩 - -#### ת - -? ֵַ͵Ļת -? string myString = "Hello"; -? int myInt = int.Parse(myString); -? - - double score = 92.6; - string myString = score.ToString( ); - - double score = 59.3; - int myInt = Convert.ToInt32 (score); - -## C# - -#### һʼ - - óʼС - int [ ] arr = new int[5]{0,1,2,3,4,}; - int [ ] arr = new int [ ]{0,1,2,3,4,}; (ʡԳ) - int [ ] arr = {0,1,2,3,4,}; (ʡnew) - -#### ö - -? ڶһضֵ -? öenumؼ -? enum student -? { -? ѧ -? } - -#### foreach - -? foreach(ͣԪأinϻ) -? { -? -? } - - - -#### ġά - -``` -int[,] arr = {{1,2,3},{4,5,6},{7,8,9}}; -for (int i = 0; i < arr.GetLength(0); i++) - { -for (int j = 0; j < arr.GetLength(1); j++) - { - Console.WriteLine(arr[i, j]); - } - } -``` - -άı -**һֱ** -for (int i =0; i =,<,>, - -==比较字符串:a.Equals("")== - -#### 3.逻辑运算符: - -&&:与 ||:或 !:非 - -#### 4.三元运算符 - -(条件表达式A)?A为true:A为false - -例如:如果a>5?输出大于:否者输出小于 - -``` -Console.WriteLine("a{0}5",a>5?"大于":"小于"); -``` - -***** - -## (7)收起代码 - -代码前一行:#region 名字 代码最后一行:#endregion - -***** - -## (8)选择分支结构 - -#### 1.if语句: - -```c# -if (a >= 80)//判断条件 -{ -Console.WriteLine("优秀"); -} -else if (a >= 60) -{ -Console.WriteLine("合格"); -} -else//否则 -{ -Console.WriteLine("不及格"); -} -``` - -#### 2.swich语句 - -```c# -switch (a) -{ -case 1:Console.WriteLine("星期一"); break; - //与Java不同结尾必须加上break -case 2: Console.WriteLine("星期二"); break; -case 3: Console.WriteLine("星期三");break; -default: Console.WriteLine("输入错误"); break; -} -``` - -***** - -## (9)循环结构 - -#### 1.while循环 - -```c# -int i=1;//初始值 -while (i <= 10)//判断条件 -{ -sum = sum + i;//循环体 -i++;//迭代 -} -Console.WriteLine(sum); -``` - -#### 2.for循环 - -```c# -int sum = 0; -for (int i = 1; i <= 100; i++)/条件初始化 条件判断 迭代 -{ -sum += i;//循环体 -} -Console.WriteLine(sum); -``` - -#### 3.foreach循环: - -不知道循环的次数时使用 - - -```c# -int[] arr1 = { 1, 2, 3, 4, 5 }; -int sum = 0; -foreach (int i in arr1)//arrl是一个变量可以换变量名 -{ -Console.WriteLine(i); -} -运行结果是把数组一个一个竖着输出 -``` - -```c# -//统计输入有多少字符,多少数字,多少特殊符号。 -//根据AscII表 -//统计字符 -int countChar = 0, countNumber = 0, countSym = 0; -Console.WriteLine("请输入一串字符:"); -string str = Console.ReadLine(); //fakghiag 4#&$#E -foreach (char j in str) -{ -if (j >= 'A' && j <= 'Z' || j >= 'a' && j <= 'z') -{ -countChar++; -} -else if (j >= '0' && j <= '9') -{ -countNumber++; -} -else -{ -countSym++; -} -} -Console.WriteLine("数字{0},字母{1},特殊符号{2}", countNumber, countChar, countSym); -``` - - - -#### ==4.可在循环过程中添加的语句== - -break语句: 在多层循环中, 一个break语句只向外跳一层。 -continue语句: 作用是跳过循环体中剩余的语句并到循环末尾而强行执行下一次循环。 - -***** - -# 二、数组与枚举 - -## (1)一维数组的声明与初始化 - -#### 1.数组的声明 - -```c# -int[] arr;//声明 -arr = new int[5];//初始化 -``` - -#### 2.数组的初始化 - -```c# -//1.静态初始化:给定数组长度和元素 -//与Java中不同的是,int arr[]在C#中将变得不可用 -int[] arr = new int[]{1,3,5,6,7}; //int[] arr = {1,3,5,6,7}; -var arr = new string[]{"1","2","3"};//var arr = {"1","2","3"}; - -//2.动态初始化:给定数组长度,但是元素不赋值 -int[] arr = new int[5]; -var arr = new int[5]; -``` - -## (1.1)数组的动态赋值 - -#### 1数组赋值 - -数组如果不赋值,将会有默认值,其中,int型数组默认值是0,浮点型默认值是0.0,bool默认值是false,string默认值是null,其它引用类型默认值也是null。 - -```c# -var arr = new int[5]; -//一个个赋值 -arr[0] = 0; -arr[1] = 1; -arr[2] = 2; -arr[3] = 3; -arr[4] = 4; -//利用循环赋值 -for(int i = 0; i<5;i++) -{ - arr[i] = i-1; -} -``` - -#### 2.获取数组长度 - -数组下标最大值 = 数组长度-1 - -```c# -int len = arr.Length; -int maxIdx = arr.Length - 1; -Console.WriteLine("数组arr的长度是:{0}",len); -Console.WriteLine("数组下标最大值:{0}",maxIdx); -``` - -********* - -## (2)一维数组的遍历 - -==数值的长度==:b.Length - -#### 1.第一种遍历 - -```c# -for (int i = 0; i < b.Length; i++) -{ -Console.WriteLine(b[i]); -} -``` - -#### ==2.第二种遍历foreach== - -```c# -foreach (int i in b) { Console.WriteLine(i); }//只读,不能修改。( 引用类型可以修改) -``` - -****** - -## (3)二维数组的声明 - -矩形数组:矩阵数组也称为多维数组,声明等长的二维数组 - -交错数组:几行几列不规则使用下面a的声明方法 - -```c# -//交错数组,动态初始化 -int [][]a=new int [4][];//定义4列,从0到3列 -int a[0]=new int [5];//再次定义行的个数,第一列有5个 - -//矩形数组,动态初始化 -int[,] c = new int[4, 5]; - -//静态初始化 -int[,] d = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } } ; - -int[,] arr = new int{{1,2,3,4},{5,6,7,8},{9,10,11,12}}; -``` - -C#中,我们在创建二维数组的时候,一般使用arr[][]的形式,例如 - -int[][] aInt = new int[2][]; - -但声明二维数组还有一种方法,是使用arr[,]的形式。两者有什么区别呢? - -实际上,形如arr[,]只能声明等长的二维数组,例如 - -```c# -int[,] ab1 = new int [2,3];//默认值为0; -int[,] ab2 = new int[2,3]{{1,2,3},{4,5,6}}; -``` - -形如arr[][]的形式则可以声明等长二维数组,也可以声明不等长二维数组。例如 - -```c# -int [][] abc = new int[2][]; -abc[0] = new int[]{1,2}; -abc[1] = new int[]{3,4,5,6}; -``` - -C#的不规则二维数组可以理解为 保存一维数组的数组 - -***** - -## (4)二维数组的遍历 - -#### 1.第一种遍历 - -方法:==GetLebgth(几维)== - -```c# -for (int i = 0; i < arr.GetLength(0); i++) -{ -for (int j = 0; j < arr.GetLength(1); j++) -{ -Console.WriteLine(arr[i, j]); -} -} -``` - -#### 2.第二种遍历foreach - -```c# -foreach (var i in arr) -{ -Console.WriteLine(i); -} -``` - -***** - -## (5)生成随机数 - -关键字:Random,Next - -```c# -Random a = new Random(); -int[] ar = new int[10]; -for (int I =0;I bub[j + 1])//+1记得上面长度-1,不然会溢出 - {//交换过程 - int temp = bub[j]; - bub[j] = bub[j + 1]; - bub[j + 1] = temp; - } - } -} -``` - -***** - -## (7)习题 - -#### 1.逆序输出 - -4.将一个数组中的元素逆序输出,即第一个元素和最后一个元素交换, - //第二个数与倒数第二元素交换…..,例如:原数组为:9 2 5 7 8, -//逆序后的数组为:8 7 5 2 9 - -```c# - int[] arr2 = new int[5]; - for (int i = 0; i < arr2.Length; i++) - { - arr2[i] = Convert.ToInt32(Console.ReadLine()); - } - //逆序 - //9 2 5 7 8第一次运行 - //8 2 5 7 9第二次运行 - //8 7 5 2 9第三次运行 运行到这就可以了,继续运行会导致数组交换回去(除于二的原因) - //8 7 5 2 9第四次运行 - int t; - for (int i = 0; i < arr2.Length / 2; i++)//除2 - { - t = arr2[i]; - arr2[i] = arr2[arr2.Length - 1 - i]; - arr2[arr2.Length - 1 - i] = t; - } -``` - -#### 2.输出数组中的最大最小值 - -```c# - Random a = new Random(); - - int[] ar = new int[10]; - - for (int I = 0; I < ar.Length; I++) - { - ar[I] = a.Next(10); - - }//生成随机数 - int MAX = ar[0];//定义最大最小值 - int MIN = ar[0]; - for (int i = 0; i < ar.Length - 1; i++) - { - MAX = MAX < ar[i + 1] ? ar[i + 1] : MAX; -//错误代码:MAX = ar[i] < ar[i + 1] ? ar[i + 1] : ar{i};(导致是两两比较最后输出的是倒1,2的比较结果 - //三元运算符分解 - //4 2 5 48 6 4 - //if (MAX < ar[i + 1]) - //{ - // MAX = ar[i + 1]; - //} - MIN = MIN > ar[i + 1] ? ar[i + 1] : MIN; - } - - Console.WriteLine(MAX + " " + MIN); -``` - -***** - -## (8)方法的==枚举== - -关键字:==enum==(希望得到一个固定集合的值,就采用枚举) - -```c# -public enum week //在命名空间内部或类声明枚举,它与结构的作用类似,所以位置一样,但同时枚举也可以在结构中被调用 -{ -//默认情况下,每一个值都会根据定义的顺序从0开始,自动赋予每一个值一个整型,所以强转int类型不会报错并且输出为数值 -//也可以人为指定如指定星期一, - 星期二, - 星期三, - 星期四=4,//也可以人为指定 - 星期五, - 星期六=10, - 星期日 -}; -``` - -#### 1.遍历枚举元素 - -```c# - enum student - { - 周飘, - 金星=10, - 曾鹏 - }; -//遍历 -Foreach(var i in Enum.GetValues(typeof(weekday))) -{ -Console.WriteLine(i); -} -``` - -#### 2.枚举的转换(扩展) - -```c# -Gender zs = Gender.男; -Console.WriteLine((int)zs); -//(int)实现将枚举转换为整型 -Console.WriteLine(zs.ToString()); - -int myint = 10; -Console.WriteLine((week)myint);//int转换为枚举,因为定义星期六=10,所以输出星期六 -//(枚举名)实现整型举转换为将枚 - -week myWorkDay = week.星期四; -Console.WriteLine((int)myWorkDay); - -//将枚举转换为字符串 不能用(string)只能用myWorkDay.ToString();或者Convert.ToString(myWorkDay); -Console.WriteLine(myWorkDay); - -//将字符串转换为枚举值 -string mystr2 = "星期五"; -Console.WriteLine((week)Enum.Parse(typeof(week), mystr2)); -//(要枚举的类型)Enum.Parse(typeof(要枚举的类型), 要转换的字符串)); -//如果转换的字符串是数字,则就算枚举中没有,也不会异常 -//如果转换的字符串是文本,如果枚举中没有,则会异常 -``` - -***** - -## (9)扩展:params关键字 - -```c# -static int arr(params int[] arr1)//params关键字主要用于个数不定的情况(删除上面数组中的几个数也不影响运行结果) - { - int sum = 0; - foreach (int i in arr1) - { - sum += i; - } - return sum; - } -``` - - - -## ==(10)基础总结== - -C#中的数据类型 - -常量和变量的语法相同点和不同点 - -C#中算术运算符、比较运算符和逻辑运算符的语法 - -分支结构:多重分支,嵌套if和switch结构 - -循环结构:for、while、do-while和JAVA语言一样。 - -foreach 循环用来遍历一个集合或者数组里的每一个元素 - -C#语言数组的定义和JAVA的区别 - -数组和循环的结合使用,冒泡排序的实现 - -枚举是自定义类型,可以为每个元素进行赋值一个常量 - -数据类型的转换:隐式类型转换是自动的 - -字符串和数值类型之间的转换 - -***** - -# 三、方法 - -## (1)方法的作用 - -简化,重用代码。使得代码可读性强。 - -***** - -## (2)方法的格式 - -访问修饰符:public(公共的),private(私有的),protected(受保护的),internal(内部的),static: 静态的 - -返回值类型:void:无返回值,有返回:int,double,char,bool,string,int[]; - -##### a.形式参数: - -就是在定**义函数或过程的时候命名的参数。** 通俗讲就是一个记号。 - -```c# -访问修饰符 返回值类型 方法名(形式参数) -public static void accu() -``` - -***** - -## (3)定义&调用方法 - -#### 1.定义方法 - -##### a.无返回值 - -```c# -访问修饰符 static 无返回值[返回值类型] 方法名(形式参数) -public static void accu() -{ - int sum = 0; - for(int i = 1; i <= 10;i++) - { - sum += i; - } -} -``` - -##### b.有返回值: - -注意事项:return - -```c# -访问修饰符 静态的 返回值类型 方法名(形式参数) -public static int getMax(int c, int d) -{ - int sum = 0; - c += 5; - d -= 2; - sum=c+b; -return sum;//返回 sum -} -``` - -​ - -定义相当于做好了一个工具,等待后面使用它。 - -#### 2.如何调用方法? - -##### a.实际参数: - -就是在执行时,调用函数或过程时,传递给函数或过程的参数。 通俗讲就是实际值。 - -##### b.静态方法 - -```c# -class Program//program 类 -{ - int slbl = 0;//默认变量都是实例变量/实例成员 - static int jt = 0;//静态变量/静态成员 - -public static void Main(String[] args)//静态方法 -{ - accu(实际参数);//无返回值调用 - Console.WriteLine(accu(实际参数)); - //有返回值调用 - - - //无法在静态方法中调用实例类成员 - //静态方法中不允许使用this -} -} -``` - -主方法必须是static的,因为这个方法不能依赖任何该类的实例即可运行,而**非static的方法,在运行之前要先创建该类的实例对象**。 - -##### ==b.调用非静态方法&类的实例化== - -```c# -class Program - { - public static void Main(string[] args) - { - //将类进行实例化 - Program p = new Program();//类的实例 - p.hi();//调用实例方法时必须使用类的实例或对象来引用 - - //实例中可以调用任何成员,包括静态和实例类的 - - Program.hi();//不能通过访问静态方法的途径去访问实例方法 - } - public extern void hi()//实例方法 - { - Console.Write("Hello C#"); - } - } -``` - -***** - -## (4)方法的参数传递机制 - -​ 方法在Java中只有一个值传递,但是在C#中,可以有value(值传递),ref(引用传递)和out(输出传递) - -​ 值传递只能返回一个,ref,out可以返回多个值 -​ value:实参和形参互相独立, 只进不出 -​ ref:能改变实际参数的值, 又进又出 -​ out : 只出不进 - -其中,ref和out使用效果上面是等效的,它们的区别在于:参数标记为ref,那么必须在调用函数之前==初始化参数==的值;参数标记为out,调用函数之前==不需要初始化对象==,但调用的函数必要在函数返回之前为对象赋值 - -```c# -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j)//ref关键字(必须是一个非常量、必须初始化) - //调用用时也要加上ref - { - j++; - } - - public static void OutFun(out int k)//out关键字(当希望返回多个值时使用) - //和ref的区别:可以不用初始化变量 - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - //ref调用 - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - //out调用 - int k;//不需要变量初始化,直接定义 - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} - -``` - -***** - -## (5)方法的重载 - -重载:方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 - -```C# -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -//1.形参个数不同: 1和2 -//2.相同个数,形参类型不同:1,3,4 -//3.形参数据类型顺序不一致 -``` - -#### 1.练习: - -​ //利用重载求圆、矩形、三角形的面积 r 长宽 abc三条边长 -​ //求三角形面积:海伦公式 s=√p(p-a)(p-b)(p-c) p为三角形周长的一半 -​ //根号用System.Math.Sqrt();代表,写在同一个类中,求圆的面积 - - -```c# - static void area(int r) - { - double pai = 3.14; - double area = pai * r * r; - Console.WriteLine("您求的圆的面积是:" + area); - } - - //求矩形的面积 - static void area(int w, int l) - { - int area = l * w; - Console.WriteLine("您求的矩形的面积是:" + area); - } - - //求三角形的面积 - static void area(int a, int b, int c) - { - double p = (a + b + c )/ 2; - double area=System.Math.Sqrt(p*(p-a)*(p-b)*(p-c)); - Console.WriteLine("您求的三角形的面积是:" + area); - } - static void Main(string[] args) - { - //利用方法的重载进行调用方法 - area(3,4,5);//三角形 - area(5);//圆 - area(10,20);//矩形 - Console.ReadLine(); - } -``` - -***** - -## (6)递归 - -​ 方法自己调用自己,递归2要素:①递归出口 ②递归表达式 - -***** - -## (7)扩展:虚方法 - -```c# - class class1 - { - //默认的方法被指定为私有的,只能在当前类中进行访问 - //需要在其他内容访问,就需要将其指定为public:访问权限最高,只要在项目内部都可以进行访问 - //virtua关键字必须位于viod前 - //有vritual关键字叫虚方法 - public virtual void virtualmehtod()//虚方法能够在派生类中重写 - { - Console.WriteLine("这是一个虚方法"); - //虚方法的实现可以由派生类取代,取代所继承的虚方法的实现过程称之为:重写(override)改方法 - } - public void novirtualmehtod() - { - Console.WriteLine("这是一个非虚方法"); - //非虚方法的实现是一成不变的 - } - } - - class class2 : class1//将class2继承于class1 - { - //重写一下虚方法 - public override void virtualmehtod() - { - Console.WriteLine("这是一个新写的虚方法"); - } - - public new void novirtualmehtod() - { - Console.WriteLine("这是一个新方法"); - } - } - static void Main(string[] args) - { - class1 c1 = new class1();//将类进行实例化 - c1.virtualmehtod();//调用虚方法 - c1.novirtualmehtod();//调用非虚方法 - class2 c2 = new class2(); - - c2.virtualmehtod(); - c2.novirtualmehtod(); - c1 = c2; - c1.virtualmehtod(); - c1.novirtualmehtod(); - } -} -``` - -***** - -## (8)扩展:重写方法 - -```c# -class class1//新建一个类存放虚方法 -{ - public virtual void wfite() - { - Console.WriteLine("这是一个虚方法,它可以被重写"); - } -} - -//再新建一个继承类用于重写方法 - -class class2 : class1 -{ - //重写方法 - public override sealed void wfite()//重写方法签名不变:void wfite - //public (可访问性):重写声明不能更改所对应的虚方法的可访问性 - { - Console.WriteLine("这是一个重写的方法,被称为已经重写了的基方法"); - } -} -//如果我不想让继承class2的类重写write()方法,应该怎么做呢? -//那就采用关键字sealed -class class3 : class2 -{ - public override void wfite()//当我们不希望别人重写我们的方法时使用sealed关键字 - //(加在原来的方法 void 的前面) - { - Console.WriteLine("这是我再次重写的方法"); - } -} - -internal class Program -{ - static void Main(string[] args) - { - class1 c1 = new class1();//类的实例化 - c1.wfite(); - class2 c2 = new class2(); - c2.wfite(); - Console.ReadKey(); - } -} -``` \ No newline at end of file diff --git "a/38\345\274\240\351\235\231/\347\254\224\350\256\2604.7\347\261\273\344\270\216\345\257\271\350\261\241\347\232\204\346\267\261\345\205\245\357\274\232.md" "b/38\345\274\240\351\235\231/\347\254\224\350\256\2604.7\347\261\273\344\270\216\345\257\271\350\261\241\347\232\204\346\267\261\345\205\245\357\274\232.md" deleted file mode 100644 index 41cba151b6b28296e2174d525aa320df50eed77d..0000000000000000000000000000000000000000 --- "a/38\345\274\240\351\235\231/\347\254\224\350\256\2604.7\347\261\273\344\270\216\345\257\271\350\261\241\347\232\204\346\267\261\345\205\245\357\274\232.md" +++ /dev/null @@ -1,93 +0,0 @@ -# 笔记: - -## 类与对象深入 - -#### (1)值类型和引用类型 - -值类型数据和引用类型数据作为方法的参数时之间的差异: - -![image-20220407213152315](C:\Users\lenovo\AppData\Roaming\Typora\typora-user-images\image-20220407213152315.png) - -![image-20220407213318301](C:\Users\lenovo\AppData\Roaming\Typora\typora-user-images\image-20220407213318301.png) - -#### (2)栈内存与堆内存 - -1. 栈区:由编译器自动分配释放 ,存放值类型的对象本身,引用类型的引用地址(指针), - 静态区对象的引用地址(指针),常量区对象的引用地址(指针)等。其操作方式类似于数据结构中的栈。 - -2) 堆区(托管堆):用于存放引用类型对象本身。在c#中由.net平台的垃圾回收机制(GC)管理。 - 栈,堆都属于动态存储区,可以实现动态分配。 -3) 静态区及常量区:用于存放静态类,静态成员(静态变量,静态方法),常量的对象本身。 - 由于存在栈内的引用地址都在程序运行开始最先入栈,因此静态区和常量区内的对象的生命周期 - 会持续到程序运行结束时,届时静态区内和常量区内对象才会被释放和回收(编译器自动释放)。 - 所以应限制使用静态类,静态成员(静态变量,静态方法),常量,否则程序负荷高。 - -#### (3)装箱与拆箱 - -装箱: -将值类型装换为引用类型 -隐式操作 - int value = 9; - Object obj = value; - -拆箱: -将引用类型转换为值类型 -显示操作 - int value = 10; - Object obj1 = value; - int b = (int)obj1; - -作业: - -1. - -namespace ConsoleApp2 - -{ - - class Student - - { - -​ public string stuName; - -​ public int stuAge; - -​ public string stuSex; - -​ public int tcAge = 25; - - - -​ public Student(string StuName,int StuAge,string StuSex) - -​ { - -​ this.stuName = StuName; - -​ this.stuAge = StuAge; - -​ this.stuSex = StuSex; - -​ Console.WriteLine("他的姓名是{0},性别是{1},年龄是{2}", StuName, StuAge, StuSex); - -​ } - -​ public void SayHello() - -​ { - -​ stuName = "mary"; - -​ stuSex = "男"; - -​ stuAge = 28; - -​ Console.WriteLine("他的姓名是{0},性别是{1},年龄是{2}", stuName, stuAge, stuSex); - -​ } - - } - -} - diff --git "a/38\345\274\240\351\235\231/\347\261\273\344\270\216\345\257\271\350\261\241\345\210\235\345\247\213\344\275\234\344\270\232.md" "b/38\345\274\240\351\235\231/\347\261\273\344\270\216\345\257\271\350\261\241\345\210\235\345\247\213\344\275\234\344\270\232.md" deleted file mode 100644 index f61755f554c28d71178c6517f09fdc11f102dc1c..0000000000000000000000000000000000000000 --- "a/38\345\274\240\351\235\231/\347\261\273\344\270\216\345\257\271\350\261\241\345\210\235\345\247\213\344\275\234\344\270\232.md" +++ /dev/null @@ -1,148 +0,0 @@ - // 一、创建一个控制台应用程序,该程序名为ClassTest, - -​ //在该程序中创建一个以Role为类名的、包含以下成员的一个类。 - -​ //角色名、性别、出处、地位、门派地位、爱侣、父亲、母亲: - -```c# -namespace ConsoleApp1 - -{ - - class Class1 - - { - -​ public string roleName; - -​ public string gender; - -​ public string provenance; - -​ public string status; - -​ public string fstatus; - -​ public string lovers; - -​ public string father; - -​ public string mother; - - - - - -​ public Class1(string RoleName, string Gender, string Provenance, - -​ string Status, string Fstatus, string Lovers, string Father, string Mother) - -​ { - -​ this.roleName = RoleName; - -​ this.gender = Gender; - -​ this.provenance = Provenance; - -​ this.status = Status; - -​ this.fstatus = Fstatus; - -​ this.lovepartner = Lovers; - -​ this.father = Father; - -​ this.mother = Mother; - -​ } - -​ public void plase() - -​ { - -​ Console.WriteLine("{0},{1}的主角,是{2},{3},{4},他的爱人是{5},父亲是{6},母亲是{7}", - -​ roleName, gender, provenance, status, fstatus, lovepartner, father, mother); - -​ } - - } - -} - -namespace ConsoleApp1 - -{ - - class Program - - { - -​ static void Main(string[] args) - -​ { - -​ Class1 p = new Class1("张无忌", "男", "倚天屠龙记", "主角", "明教教主", "赵敏", "张翠山", "殷素素"); - -​ p.plase(); - -​ Console.WriteLine(); - -​ } - - } - -} -``` - -二、用于模拟银行账户(Account类),要求有初始化余额(balance),存取现金操作和查看余额的操作 - -初始化余额有两种方式,默认余额(1000)和客户指定余额 - -提示: - -1、定义一个Account类 - -```c# -static void Main(string[] args) -{ - Account m = new Account(); - Console.WriteLine("输入1查看余额,输入2存款,输入3查看余额"); - int a = Convert.ToInt32(Console.ReadLine()); - - -​ if (a == 1)//查看余额 -​ { -​ m.examine(); -​ -​ } -​ else if (a == 2)//存款 -​ { -​ m.save(); -​ -​ } -​ else if (a == 3) //取款 -​ { -​ m.draw(); -​ -​ } -​ else -​ { -​ Console.WriteLine("输入错误请重新输入"); -​ -​ } -​ -​ Console.ReadLine(); -} -``` - -2、声明成员变量balance表示余额 - -​ public decimal balance; - -3、编写一个无参的构造方法,设置默认余额为1000 - -4、编写一个有参的构造方法,让客户指定余额 - -5、编写三个成员方法,分别表示存钱,取钱和查看余额 \ No newline at end of file diff --git "a/39\345\217\266\345\260\217\346\235\260/\344\275\234\344\270\2321.md" "b/39\345\217\266\345\260\217\346\235\260/\344\275\234\344\270\2321.md" deleted file mode 100644 index 210c0a4869777214143e61822bc27f0d82747d99..0000000000000000000000000000000000000000 --- "a/39\345\217\266\345\260\217\346\235\260/\344\275\234\344\270\2321.md" +++ /dev/null @@ -1,50 +0,0 @@ -using System; - -namespace ClassTest -{ - class Program - { - private Role h = new Role("޼", "", "", "", "̽", "", "Ŵɽ", ""); - h.Role; - - } -} - - -using System; -using System.Collections.Generic; -using System.Text; - -namespace ClassTest -{ - class Role - { - public string name; - public string gander; - public string provenance; - public string status; - public string ustatus; - public string lover; - public string father; - public string mother; - - public Role(string Name, string Gander, string Provenance, string Status, string Ustatus, string Lover, string Father, string Mother) - { - this.name = Name; - this.gander = Gander; - this.provenance = Provenance; - this.status = Status; - this.ustatus = Ustatus; - this.lover = Lover; - this.father = Father; - this.mother = Mother; - } - public void role - { - Console.WriteLine( - Name,Gander,Provenance,Status,Ustatus,Lover, Father, Mother) - } - } - -} - diff --git "a/40\345\221\250\351\243\230/C#\347\254\224\350\256\260.md" "b/40\345\221\250\351\243\230/C#\347\254\224\350\256\260.md" deleted file mode 100644 index a5f5213fabb8b94fd84a721c0413705e6c847ddb..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\347\254\224\350\256\260.md" +++ /dev/null @@ -1,599 +0,0 @@ -C#数据类型; -(1)int(存储32位有符号整数) -(2)float(存储单精度(精确到7位小数)浮点数) -(3)double(存储双精度(精确到16位小数)浮点数) -(4)decimal(存储高精度十进制数据(精确到28位小数)) -(5)byte(存储8位无符号整数) -(6)short(存储16位有符号整数) -(7)long(存储64位有符号整数) -(8)bool(布尔型,值为true或false) -(9)string(字符串类型) -(10)char(字符类型) - -算术运算符 -(1) + (执行加法运算,如果+号两端有一个操作数是字符串,则执行字符串的连接运算 ) int a=1,b=2; int c=a+b; - (2) - (执行减法运算) c=a-b; - (3) * ( 执行乘法运算) c=a*b; - (4) / (执行除法运算) c=a/b; - (5) % (获取除法运算后的余数) c=a%b: - (6) ++ (将操作数加1) a++; - (7) -- (将操作数减1) b--; - (8) ~ (将一个数按位取反) ~a; - - - -比较运算符 - (1)> (判断一个数是否大于另一个数) a>b - (2)< (判断一个数是否小于另一个数) a= (判断一个数是否大于或等于另一个数 )a>=b - (4)<= (判断一个数是否小于或等于另一个数) a<=b - (5)== (判断两个值是否相等) a==b - (6)!= (判断两个值是否不相等) a!=b - - -逻辑运算符 - (1) && (对两个表达式执行逻辑“与”运算 )操作数1&&操作数2 - (2) || ( 对两个表达式执行逻辑“或”运算 )操作数 11操作数2 - (3 ) ! ( 对一个表达式执行逻辑“非”运算) !操作数 - - -快捷运算符 - (1)+= 左边变量的数值加上右边的值,然后赋值给该变量 int a=1; a+=1; - (2)-= 左边变量的数值减去右边的值,然后赋值给该变量 a-=1; - (3) *= 左边变量的数值乘以右边的值,然后赋值给该变量 a*=5; - (4)/= 左边变量的数值除以右边的值,然后赋值给该变量 a/=5; - (5) %= 左边变量的数值求模右边的值,然后赋值给该变量 a%=5; - - -三元运算符 -“ a>b ? a:b ” - - -变量的定义 -(1)变量名必须以字母或者下画线开头。 -(2)变量名只能由字母、数字和下画线组成,而不能包含空格、标点符号、运算符等其他符号。 -(3)变量名不能与C#中的关键字名称相同,如int、float、double 等。 -(4)变量名是区分大小写的。也就是说,abc和ABC是两个不同的变量。 - - -变量的赋值 -int a=convert。toINT32(console.ReadLine()); - - -条件判断结构(if......else.....)(switch.....case....) -if(判断条件1) -{ - 代码块1 -} -else if(判断条件2) -{ - 代码块2 -} -else -{ - 代码块3 -} - -switch(常量) -{ -case值1 - 语句块1 - break; -case值2 - 语句块2 - break; -case值3 - 语句块3 - break; -... -default: - 语句块4 - break; -} - - -循环结构(while,do...while,for,foreach) -while(条件表达式) -{ - 代码块 -} - -do -{ - 代码块 -}while(条件表达式) - -for(表达式1;表达式2;表达式3;...) -{ - 代码块 -} - -foreach(类型(集合或数组中每个元素的类型)变量名in集合或数组) -{ - 代码块 -} - - -var初始化 - Var number=2009; - var strs=new string[ ]{“2008”,“2009”,“80”“20”}; - var ui= new UserInfo(); - ==>> int number=2009; - string [ ]strs=new string[ ]{“2008”,“2009”,“80”“20”}; - userinfo ui= new UserInfo(); -使用: -第一范围,可以在声明局部变量时使用,for语句中,foreach语句中,using语句中; -第二原则:必须包含一个初始化器;声明的变量初始化值不能为null;不能同一语句初始化多个隐式类型变量。 - - -数组(矩阵数组,交错数组) - 数组是同一数据类型的一组数据,这些值存储在连续的内存单元中,便于访问和操作。数组中的所有数据必须是相同的数据类型,不能将数据类型不同的数据存储在同一个数组中。而且不管数组中有多少个元素,数组都只有一个数组名。 -定义数组的语法如下: -int[6]arr ; - -string[] arr1= new string[5]; - -string[] arr2 ={"top". "down", "left". "right"} ; - -数组的声明 -int[] arr;//声明 -arr = new int[5];//初始化 - - -数组的初始化 -(1)静态初始化:给定数组长度和元素 -(2)与Java中不同的是,int arr[]在C#中将变得不可用 -(3)int[] arr = new int[]{1,3,5,6,7}; //int[] arr = {1,3,5,6,7}; -(4)var arr = new string[]{"1","2","3"};//var arr = {"1","2","3"}; - -动态初始化:给定数组长度,但是元素不赋值 -int[] arr = new int[5]; -var arr = new int[5]; - - -数组的动态赋值 -数组赋值 - 数组如果不赋值,将会有默认值,其中,int型数组默认值是0,浮点型默认值是0.0,bool默认值是false,string默认值是null,其它引用类型默认值也是null。 -var arr = new int[5]; -一个个赋值 -arr[0] = 0; -arr[1] = 1; -arr[2] = 2; -arr[3] = 3; -arr[4] = 4; -利用循环赋值 -for(int i = 0; i<5;i++) -{ - arr[i] = i-1; -} -``` -获取数组长度 -数组下标最大值 = 数组长度-1 -int len = arr.Length; -int maxIdx = arr.Length - 1; -Console.WriteLine("数组arr的长度是:{0}",len); -Console.WriteLine("数组下标最大值:{0}",maxIdx); - - - 一维数组的遍历 -数值的长度:b.Length - -第一种遍历 -for (int i = 0; i < b.Length; i++) -{ -Console.WriteLine(b[i]); -} -``` - -第二种遍历foreach -foreach (int i in b) { Console.WriteLine(i); }//只读,不能修改。( 引用类型可以修改) - - - -二维数组的声明 -矩形数组:矩阵数组也称为多维数组,声明等长的二维数组 -交错数组:几行几列不规则使用下面a的声明方法 - - -交错数组,动态初始化 -int [][]a=new int [4][];//定义4列,从0到3列 -int a[0]=new int [5];//再次定义行的个数,第一列有5个 - -矩形数组,动态初始化 -int[,] c = new int[4, 5]; - -静态初始化 -int[,] d = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } } ; -int[,] arr = new int{{1,2,3,4},{5,6,7,8},{9,10,11,12}}; -``` - -C#中,我们在创建二维数组的时候,一般使用arr[][]的形式,例如 - -int[][] aInt = new int[2][]; - -但声明二维数组还有一种方法,是使用arr[,]的形式。两者有什么区别呢? - -实际上,形如arr[,]只能声明等长的二维数组,例如 -int[,] ab1 = new int [2,3];//默认值为0; -int[,] ab2 = new int[2,3]{{1,2,3},{4,5,6}}; - - -形如arr[][]的形式则可以声明等长二维数组,也可以声明不等长二维数组。例如 -int [][] abc = new int[2][]; -abc[0] = new int[]{1,2}; -abc[1] = new int[]{3,4,5,6}; - - -C#的不规则二维数组可以理解为 保存一维数组的数组 - - -二维数组的遍历 - -第一种遍历 -GetLebgth(几维) -for (int i = 0; i < arr.GetLength(0); i++) -{ -for (int j = 0; j < arr.GetLength(1); j++) -{ -Console.WriteLine(arr[i, j]); -} -} - - -第二种遍历foreach -foreach (var i in arr) -{ -Console.WriteLine(i); -} - -二维数组 -例如:int[,] arr = { {1,2,3},{4,5,6},{7,8,9} }; - - -驼峰命名法 - - 变量,方法:小驼峰:myName, myClassName() - 大驼峰:类名,命名空间,属性:public class MyDataBase - - - -字符串转换 - int num=int.Parse(Console.ReadLine()); - float.Parse(string str) 字符串转换成float类型 - double.Parse(string str) 字符串转换成double类型 - - -随机数 -例:Random a = new Random(); 'a为定义随机数' - - int[] arr = new int[10]; '自定义数组' - - for (int I =0;I - - - Exe - netcoreapp3.1 - - - diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/Program.cs" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/Program.cs" deleted file mode 100644 index aef0f9cbfc13391e98c8ba07dce6314609f75d4b..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/Program.cs" +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace ConsoleApp1 -{ - class Program - { - static void Main(string[] args) - { - Role Z = new Role("张无忌","男","倚天屠龙记","主角","明教教主","赵敏","张翠山","殷素素"); - Z.info(); - Console.ReadLine(); - - - - } - } -} diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/Role.cs" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/Role.cs" deleted file mode 100644 index cbc5726075a692f71bab3b30dc36eb1a99009d0d..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/Role.cs" +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace ConsoleApp1 -{ - class Role - { - //作业一 - //1、创建一个控制台应用程序,该程序名为ClassTest,在该程序中创建一个以Role为类名的、包含以下成员的一个类。 - //角色名、性别、出处、地位、门派地位、爱侣、父亲、母亲: - - public string roleName; - public string gender; - public string from; - public string status; - public string familystatus; - public string lovepartner; - public string father; - public string mother; - - - public Role(string RoleName, string Gender, string From, string Status, - string Familystatus, string Lovepartner, string Father, string Mother) - { - this.roleName = RoleName; - this.gender = Gender; - this.from = From; - this.status = Status; - this.familystatus = Familystatus; - this.lovepartner = Lovepartner; - this.father = Father; - this.mother = Mother; - } - public void info() - { - Console.WriteLine("角色是{0},性别为{1},来自{2},地位{3},门派地位{4},爱侣是{5},父亲是{6},母亲是{7}", roleName, gender, from, status, familystatus, lovepartner,father,mother); - } - } - -} diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.deps.json" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.deps.json" deleted file mode 100644 index 8c191444c10da9ea5a98bd9a8930d0611ae2de28..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.deps.json" +++ /dev/null @@ -1,23 +0,0 @@ -{ - "runtimeTarget": { - "name": ".NETCoreApp,Version=v3.1", - "signature": "" - }, - "compilationOptions": {}, - "targets": { - ".NETCoreApp,Version=v3.1": { - "ConsoleApp1/1.0.0": { - "runtime": { - "ConsoleApp1.dll": {} - } - } - } - }, - "libraries": { - "ConsoleApp1/1.0.0": { - "type": "project", - "serviceable": false, - "sha512": "" - } - } -} \ No newline at end of file diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.dll" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.dll" deleted file mode 100644 index 53e6cef674050a9177b60b2c74d1fe2279e3fa64..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.dll" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.exe" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.exe" deleted file mode 100644 index 4f02a6eee142fa322f3f35910a25fd235fa8a4fb..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.exe" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.pdb" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.pdb" deleted file mode 100644 index 42e6d9a57640f35ff46481f6c16255323260a8bb..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.pdb" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.runtimeconfig.dev.json" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.runtimeconfig.dev.json" deleted file mode 100644 index 376e9695b259ac7f29e24234a0bb8e9cae5b01fd..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.runtimeconfig.dev.json" +++ /dev/null @@ -1,9 +0,0 @@ -{ - "runtimeOptions": { - "additionalProbingPaths": [ - "C:\\Users\\Administrator\\.dotnet\\store\\|arch|\\|tfm|", - "C:\\Users\\Administrator\\.nuget\\packages", - "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" - ] - } -} \ No newline at end of file diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.runtimeconfig.json" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.runtimeconfig.json" deleted file mode 100644 index bc456d7868bb54ec1809da30e339cd43f0a8a09c..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp3.1/ConsoleApp1.runtimeconfig.json" +++ /dev/null @@ -1,9 +0,0 @@ -{ - "runtimeOptions": { - "tfm": "netcoreapp3.1", - "framework": { - "name": "Microsoft.NETCore.App", - "version": "3.1.0" - } - } -} \ No newline at end of file diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.dgspec.json" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.dgspec.json" deleted file mode 100644 index 11dfac9ce70de71acccb59d6415c27a37691c2fc..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.dgspec.json" +++ /dev/null @@ -1,66 +0,0 @@ -{ - "format": 1, - "restore": { - "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\ConsoleApp1.csproj": {} - }, - "projects": { - "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\ConsoleApp1.csproj": { - "version": "1.0.0", - "restore": { - "projectUniqueName": "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\ConsoleApp1.csproj", - "projectName": "ConsoleApp1", - "projectPath": "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\ConsoleApp1.csproj", - "packagesPath": "C:\\Users\\z\\.nuget\\packages\\", - "outputPath": "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\obj\\", - "projectStyle": "PackageReference", - "fallbackFolders": [ - "D:\\C#2\\NuGetPackages" - ], - "configFilePaths": [ - "C:\\Users\\z\\AppData\\Roaming\\NuGet\\NuGet.Config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" - ], - "originalTargetFrameworks": [ - "netcoreapp3.1" - ], - "sources": { - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "netcoreapp3.1": { - "targetAlias": "netcoreapp3.1", - "projectReferences": {} - } - }, - "warningProperties": { - "warnAsError": [ - "NU1605" - ] - } - }, - "frameworks": { - "netcoreapp3.1": { - "targetAlias": "netcoreapp3.1", - "imports": [ - "net461", - "net462", - "net47", - "net471", - "net472", - "net48" - ], - "assetTargetFallback": true, - "warn": true, - "frameworkReferences": { - "Microsoft.NETCore.App": { - "privateAssets": "all" - } - }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.201\\RuntimeIdentifierGraph.json" - } - } - } - } -} \ No newline at end of file diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.g.props" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.g.props" deleted file mode 100644 index 12c16de7a954735945720c92389b04cf2c3fcf04..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.g.props" +++ /dev/null @@ -1,16 +0,0 @@ - - - - True - NuGet - $(MSBuildThisFileDirectory)project.assets.json - $(UserProfile)\.nuget\packages\ - C:\Users\z\.nuget\packages\;D:\C#2\NuGetPackages - PackageReference - 6.1.0 - - - - - - \ No newline at end of file diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.g.targets" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.g.targets" deleted file mode 100644 index 3dc06ef3cc4057524bf5d2cd49936dff789cebe8..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/ConsoleApp1.csproj.nuget.g.targets" +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/.NETCoreApp,Version=v3.1.AssemblyAttributes.cs" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/.NETCoreApp,Version=v3.1.AssemblyAttributes.cs" deleted file mode 100644 index ad8dfe1a6310302587a2d0c0111d81b250eb4105..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/.NETCoreApp,Version=v3.1.AssemblyAttributes.cs" +++ /dev/null @@ -1,4 +0,0 @@ -// -using System; -using System.Reflection; -[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")] diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.AssemblyInfo.cs" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.AssemblyInfo.cs" deleted file mode 100644 index 82beda39a3c30a669ec3326d92bec5224e01bad5..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.AssemblyInfo.cs" +++ /dev/null @@ -1,23 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 此代码由工具生成。 -// 运行时版本:4.0.30319.42000 -// -// 对此文件的更改可能会导致不正确的行为,并且如果 -// 重新生成代码,这些更改将会丢失。 -// -//------------------------------------------------------------------------------ - -using System; -using System.Reflection; - -[assembly: System.Reflection.AssemblyCompanyAttribute("ConsoleApp1")] -[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] -[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] -[assembly: System.Reflection.AssemblyProductAttribute("ConsoleApp1")] -[assembly: System.Reflection.AssemblyTitleAttribute("ConsoleApp1")] -[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] - -// 由 MSBuild WriteCodeFragment 类生成。 - diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.AssemblyInfoInputs.cache" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.AssemblyInfoInputs.cache" deleted file mode 100644 index 00a6ec1177d3ecc91306379eafe8f367683f7e97..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.AssemblyInfoInputs.cache" +++ /dev/null @@ -1 +0,0 @@ -0cbac02cf6b33ab9449e1ec02e8dbba2474e8080 diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.GeneratedMSBuildEditorConfig.editorconfig" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.GeneratedMSBuildEditorConfig.editorconfig" deleted file mode 100644 index 5abf7fc5331b8691f6911e309a26e43b464ed920..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.GeneratedMSBuildEditorConfig.editorconfig" +++ /dev/null @@ -1,3 +0,0 @@ -is_global = true -build_property.RootNamespace = ConsoleApp1 -build_property.ProjectDir = C:\Users\z\Desktop\40+周飘(C#)\c-sharp-object-oriented-notes\40周飘\C#面向对象作业\ConsoleApp1\ConsoleApp1\ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.assets.cache" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.assets.cache" deleted file mode 100644 index 1dc8e7723da28dda688b2971980b14aa9d868ba0..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.assets.cache" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.AssemblyReference.cache" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.AssemblyReference.cache" deleted file mode 100644 index b03aff67b77112de862d5e3f7fb5485514c064c9..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.AssemblyReference.cache" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.CoreCompileInputs.cache" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.CoreCompileInputs.cache" deleted file mode 100644 index 3ce85783374fd5f15ad62a076a4eb736110c225d..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.CoreCompileInputs.cache" +++ /dev/null @@ -1 +0,0 @@ -07564e1a7c4655ce1bb37a28caf63a0f2b9aaff0 diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.FileListAbsolute.txt" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.FileListAbsolute.txt" deleted file mode 100644 index bcd1e5cd6337a2f3415fec4bb88a89e458513ec6..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csproj.FileListAbsolute.txt" +++ /dev/null @@ -1,13 +0,0 @@ -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp3.1\ConsoleApp1.exe -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp3.1\ConsoleApp1.deps.json -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp3.1\ConsoleApp1.runtimeconfig.json -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp3.1\ConsoleApp1.runtimeconfig.dev.json -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp3.1\ConsoleApp1.dll -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp3.1\ConsoleApp1.pdb -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\netcoreapp3.1\ConsoleApp1.csprojAssemblyReference.cache -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\netcoreapp3.1\ConsoleApp1.AssemblyInfoInputs.cache -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\netcoreapp3.1\ConsoleApp1.AssemblyInfo.cs -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\netcoreapp3.1\ConsoleApp1.csproj.CoreCompileInputs.cache -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\netcoreapp3.1\ConsoleApp1.dll -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\netcoreapp3.1\ConsoleApp1.pdb -C:\Users\Administrator\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\netcoreapp3.1\ConsoleApp1.genruntimeconfig.cache diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csprojAssemblyReference.cache" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csprojAssemblyReference.cache" deleted file mode 100644 index 75c16613d637ba1aee3feac158410536d13849e8..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.csprojAssemblyReference.cache" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.dll" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.dll" deleted file mode 100644 index 53e6cef674050a9177b60b2c74d1fe2279e3fa64..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.dll" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.exe" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.exe" deleted file mode 100644 index 4f02a6eee142fa322f3f35910a25fd235fa8a4fb..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.exe" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.genruntimeconfig.cache" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.genruntimeconfig.cache" deleted file mode 100644 index 34bedab819ef1631d37d6e87ef9a716c545a105e..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.genruntimeconfig.cache" +++ /dev/null @@ -1 +0,0 @@ -86c8e15dd33445635927cfaf398408205fd11473 diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.pdb" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.pdb" deleted file mode 100644 index 42e6d9a57640f35ff46481f6c16255323260a8bb..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/ConsoleApp1.pdb" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/apphost.exe" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/apphost.exe" deleted file mode 100644 index c4e5a406f0460e1de8136fe2ebcfb24002478e4b..0000000000000000000000000000000000000000 Binary files "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/Debug/netcoreapp3.1/apphost.exe" and /dev/null differ diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/project.assets.json" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/project.assets.json" deleted file mode 100644 index 9c9de355a3177a173b7bd5a4330b79ca7059af00..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/project.assets.json" +++ /dev/null @@ -1,72 +0,0 @@ -{ - "version": 3, - "targets": { - ".NETCoreApp,Version=v3.1": {} - }, - "libraries": {}, - "projectFileDependencyGroups": { - ".NETCoreApp,Version=v3.1": [] - }, - "packageFolders": { - "C:\\Users\\z\\.nuget\\packages\\": {}, - "D:\\C#2\\NuGetPackages": {} - }, - "project": { - "version": "1.0.0", - "restore": { - "projectUniqueName": "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\ConsoleApp1.csproj", - "projectName": "ConsoleApp1", - "projectPath": "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\ConsoleApp1.csproj", - "packagesPath": "C:\\Users\\z\\.nuget\\packages\\", - "outputPath": "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\obj\\", - "projectStyle": "PackageReference", - "fallbackFolders": [ - "D:\\C#2\\NuGetPackages" - ], - "configFilePaths": [ - "C:\\Users\\z\\AppData\\Roaming\\NuGet\\NuGet.Config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" - ], - "originalTargetFrameworks": [ - "netcoreapp3.1" - ], - "sources": { - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "netcoreapp3.1": { - "targetAlias": "netcoreapp3.1", - "projectReferences": {} - } - }, - "warningProperties": { - "warnAsError": [ - "NU1605" - ] - } - }, - "frameworks": { - "netcoreapp3.1": { - "targetAlias": "netcoreapp3.1", - "imports": [ - "net461", - "net462", - "net47", - "net471", - "net472", - "net48" - ], - "assetTargetFallback": true, - "warn": true, - "frameworkReferences": { - "Microsoft.NETCore.App": { - "privateAssets": "all" - } - }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.201\\RuntimeIdentifierGraph.json" - } - } - } -} \ No newline at end of file diff --git "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/project.nuget.cache" "b/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/project.nuget.cache" deleted file mode 100644 index 9b64462ab6f2bff7312005cb2c43e472b0f00b69..0000000000000000000000000000000000000000 --- "a/40\345\221\250\351\243\230/C#\351\235\242\345\220\221\345\257\271\350\261\241\344\275\234\344\270\232/ConsoleApp1/ConsoleApp1/obj/project.nuget.cache" +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 2, - "dgSpecHash": "4rwIgeeWTLQnVMFsY2E9/Fs0ssFEu9vy0u2AYe+w+56nY62IgLYj7t1ENR/D/5ZWD1ge9TAJS/Rb14zWiuB7yg==", - "success": true, - "projectFilePath": "C:\\Users\\z\\Desktop\\40+周飘(C#)\\c-sharp-object-oriented-notes\\40周飘\\C#面向对象作业\\ConsoleApp1\\ConsoleApp1\\ConsoleApp1.csproj", - "expectedPackageFiles": [], - "logs": [] -} \ No newline at end of file diff --git "a/47\345\267\253\346\231\250\347\276\277/C#\347\232\204\347\254\224\350\256\2601.md" "b/47\345\267\253\346\231\250\347\276\277/C#\347\232\204\347\254\224\350\256\2601.md" deleted file mode 100644 index 49bdab4e40bd5e0eb716480e9f0c4b88c6182319..0000000000000000000000000000000000000000 --- "a/47\345\267\253\346\231\250\347\276\277/C#\347\232\204\347\254\224\350\256\2601.md" +++ /dev/null @@ -1,317 +0,0 @@ -# 笔记 - -## 1 - -1. 输出 - - ```c# - Console.Write(); //不换行 - Console.WriteLine("Hello World!"); //换行 - - ``` - - - -2. 输入 - - ```c# - string a = Console.ReadLine();//默认输入的数据类型为string - Console.WriteLine(a); - - ``` - -3. 变量 - - ```c# - //规则 - //组成:52个字母(A-Z, a-z),10个数字(0-9),下划线(_) - //开头:字母或下划线 - //不能是关键字 - - - int b = 6; - string c = "abc"; - var d = 5; - ar e = "abc"; - int(32位) short(16位) byte - //有符号,无符号 - //有符号 : short(-32,768到32,767之间的有符号整数值) - //无符号 : ushort(0到65,535之间的无符号整数值) - ``` - - - -4. 常量 - - ```c# - const int e1 = 7; - ``` - -5. 数据类型 - - ```c# - //整型:byte,short,int,long, - //浮点型:float,double,char - //布尔型: bool - //小数 : decimal(4,2) 4表示长度 , 2表示小数点后位数 - decimal a1 = 4.0m;//如果没有后缀 m,则数字将被视为 double 类型并会生成编译器错误。 - - ``` - -6. 运算符 : 算术,比较,逻辑,三元 - - ```c# - //算数:+ - * / % - //赋值运算:+=,-=,*=,/=,%= - //b += 1;// b= b+1, b++,++b - //比较运算符:>,<,>=,<=,!=,== - //bool b1 = b >= 7; - //逻辑:&&, ||, ! - //三元: (条件表达式A)?A为true:A为false - int a = 5; - int b = 8; - int c = 7; - int max = a > b ? (a>c?a:c) : (b>c?b:c); - Console.WriteLine(max); - ``` - -7. 定义类型 - - ```c# - //输入一个int 数据类型 - int a1 = Convert.ToInt32(Console.ReadLine()); - ``` - - - -8. 选择结构 - - ```c# - if(条件表达式1) - { - 条件表达式1 为true,则执行 - }else if(条件表达式2) - { - 条件表达式2 为true,则执行 - }else - { - 上面都不执行则执行 - } - ``` - - - -9. 循环结构 四要素:1.初始值 2.判断条件 3.循环体 4.迭代因子 - - 1. while 循环 - - ```c# - //求 1+...+10 的和 - int i = 1; //初始值 - while (i<=10)//判断条件 - { - sum = sum + i;//循环体 - i++; //迭代因子 - } - Console.WriteLine(sum);//输出 - ``` - - 2. for 循环 - - ```c# - for(初始值;判断条件;迭代因子) - { - 循环体 - } - ``` - - 3. foreach循环 - - ```c# - //用于列举出集合中所有的元素,foreach 语句中的表达式由关键字 in 隔开的两个项组成。 - //in 左边的项是变量名,in 右边的项是集合名,用来存放该集合中的每个元素。 - foreach(数据类型 变量名 in 数组名) - { - //语句块; - } - ``` - - 示例 - - ```c# - int countChar = 0, countNumber = 0, countSym = 0; - Console.WriteLine("请输入一串字符:"); - string str = Console.ReadLine(); //fakghiag 4#&$#E - foreach (char j in str) - { - if (j >= 'A' && j <= 'Z' || j >= 'a' && j <= 'z') - //0 : 30; A: 41 ; a: 61 (参照ASCII 表) - { - countChar++; - } - else if (j >= '0' && j <= '9') - { - countNumber++; - } - else - { - countSym++; - } - } - - Console.WriteLine("数字{0},\t字母{1},\t特殊符号{2}\n", countNumber, countChar, countSym); - //Console.WriteLine($ "数字{countNumber},\t字母{countChar},\t特殊符号{countChar}\n"); - //转义字符必须在""中使用 - ``` - -10. 转义字符 - - | \n | 换行 | - | ---- | ---------------------------------------------- | - | \r | 回车 | - | \t | 制表符 | - | \f | 换页符 | - | \b | 退格 | - | \a | 响铃 | - | \e | escape(ASCII中的escape 字符) | - | \007 | 任何八进制值(这里是,007=bell(响铃)) | - | \x7f | 任何十六进制值(这里是,007=bell) | - | \cC | 一个控制符(这里是:Ctrl+c) | - | \l | 下个字符小写 | - | \L | 接着的字符均小写直到\E | - | \u | 下个字符大写 | - | \U | 接着的字符均大写直到\E | - | \Q | 在 non-word 字符前加上(自动加转义符号),直到\E | - | \E | 结束\L,\E和\Q | - | \0 | 空格 | - | | | - -## 2命名规范 - -```c# -//小驼峰 : 首个单词的首字母小写,其余单词的首字母大写 -//常用于变量,方法 -int myAge = 5; static void myClassInfo(); - -//大驼峰 : 所有单词首字母大写 -//用于类名,属性,命名空间 -public class DataBaseUser -``` - -## 3类型转换 - -```c# -1. -string myString = "Hello"; -int myInt = int.Parse(myString); -2. -double score = 92.6; -string myString = score.ToString( ); -3. -double score = 59.3; -int myInt = Convert.ToInt32 (score); - -``` - - - -## 4数组 - -### 1数组 - - - -```c# - int[] bub = { 8, 7, 4, 6, 5, 3 };//静态 - //外层for控制第几趟 - for(int i = 0; i < bub.Length; i++) - { - //每一趟找出最大往下沉 - for(int j = 0; j < bub.Length-1-i; j++) - { - if (bub[j] > bub[j + 1]) - { - int temp = bub[j]; - bub[j] = bub[j + 1]; - bub[j + 1] = temp; - } - } - } - foreach (var i in bub) - { - Console.WriteLine(i); - } - -``` - -### 2矩阵数组 - - 二维数组 同 多维数组 又称矩形数组 - -```c# -1. -int[,] myArray; - myArray = new int[2, 3];//2行 3列 - myArray[0, 0] = 1; - myArray[0, 1] = 2; - myArray[0, 2] = 3; - - - myArray[1, 0] = 4; - myArray[1, 1] = 5; - myArray[1, 2] = 6; - - - foreach (var item in myArray) - { - Console.WriteLine(item); - } - -2. -int[,] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; - - //for - for (int i = 0; i < arr.Getlength(0); i++) - { - for (int j = 0; j < arr.Getlength(1); j++) - - Console.Writeline(arr[i, j]); - } - } - - //foreach - foreach (var i in arr) - { - Console.Writeline(i); - } -``` - - - -## 5随机数 - - - -```c# -Random a = new Random();//产生随机数 -Console.WriteLine(a.Next(10)); //不包含10 -``` - -## 6枚举 - -```c# - enum student - { - 周飘, - 金星=10, - 曾鹏 - }; -//放在main 方法外 -``` - - - - - - - diff --git "a/47\345\267\253\346\231\250\347\276\277/\347\254\224\350\256\2602.md" "b/47\345\267\253\346\231\250\347\276\277/\347\254\224\350\256\2602.md" deleted file mode 100644 index a04235882b95097e44e115c6f5585b97966704b3..0000000000000000000000000000000000000000 --- "a/47\345\267\253\346\231\250\347\276\277/\347\254\224\350\256\2602.md" +++ /dev/null @@ -1,242 +0,0 @@ -## 二、数组与枚举 - -### 1.什么是数组 - -数组是一个**有序的元素序列**,如果将有限个类型相同的变量的集合命名,那么这个名称就是数组名,而组成数组的各个变量称为数组的分量,也称为数组的元素,有时也称为下标变量。 - -### 2.声明并初始化数组 - -#### 2.1数组声明 - -```C# -int[] arr;//声明 -arr = new int[5];//初始化 -``` - -![](F:\C#\笔记\image-20220331104116586.png) - -#### 2.2数组初始化 - -```c# -//1.静态初始化:给定数组长度和元素 -//与Java中不同的是,int arr[]在C#中将变得不可用 -int[] arr = new int[]{1,3,5,6,7}; //int[] arr = {1,3,5,6,7}; -var arr = new string[]{"1","2","3"};//var arr = {"1","2","3"}; - -//2.动态初始化:给定数组长度,但是元素不赋值 -int[] arr = new int[5]; -var arr = new int[5]; -``` - -### 3.数组动态赋值与遍历 - -#### 3.1数组赋值 - -数组如果不赋值,将会有默认值,其中,int型数组默认值是0,浮点型默认值是0.0,bool默认值是false,string默认值是null,其它引用类型默认值也是null。 - -```c# -var arr = new int[5]; -//一个个赋值 -arr[0] = 0; -arr[1] = 1; -arr[2] = 2; -arr[3] = 3; -arr[4] = 4; -//利用循环赋值 -for(int i = 0; i<5;i++) -{ - arr[i] = i-1; -} -``` - -#### 3.2获取数组长度 - -数组下标最大值 = 数组长度-1 - -```c# -int len = arr.Length; -int maxIdx = arr.Length - 1; -Console.WriteLine("数组arr的长度是:{0}",len); -Console.WriteLine("数组下标最大值:{0}",maxIdx); -``` - -#### 3.3遍历数组元素 - -**for遍历** - -```c# -for(int i = 0; i< arr.Length;i++) -{ - Console.Write(arr[i]+" "); -} -``` - -**foreach遍历** - -```c# -foreach(var i in arr) -{ - Console.Write(i+" "); -} -``` - -### 4.矩阵数组 - -矩阵数组也称为多维数组 - -#### 4.1二维数组 - -```c# -//静态初始化 -int[,] arr = new int{{1,2,3,4},{5,6,7,8},{9,10,11,12}}; -// -int[][] arr = new int[5][]; -int[,] arr2 = new int[3,3]; -``` - - - - - -C#中,我们在创建二维数组的时候,一般使用arr[][]的形式,例如 - -int[][] aInt = new int[2][]; - -但声明二维数组还有一种方法,是使用arr[,]的形式。两者有什么区别呢? - - - -实际上,形如arr[,]只能声明等长的二维数组,例如 - -int[,] ab1 = new int [2,3];//默认值为0; int[,] ab2 = new int[2,3]{{1,2,3},{4,5,6}}; - - - -形如arr[][]的形式则可以声明等长二维数组,也可以声明不等长二维数组。例如 - -int [][] abc = new int[2][]; abc[0] = new int[]{1,2}; abc[1] = new int[]{3,4,5,6}; - - - -C#的不规则二维数组可以理解为 保存一维数组的数组 - - - -## 三、方法 - -### 1. 方法的作用 - -简化,重用代码。使得代码可读性强。 - -### 2.定义&调用方法 - -​ 定义方法 - -```c# -访问修饰符 static 返回值类型 方法名() -public static void accu() -{ - int sum = 0; - for(int i = 1; i <= 10;i++) - { - sum += i; - } -} -``` - -​ 定义相当于做好了一个工具,等待后面使用它。 - -​ 如何调用方法? - -```c# -public static void Main(String[] args) -{ - accu(); -} -``` - -![image-20220330174424816](C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220330174424816.png) - -主方法必须是static的,因为这个方法不能依赖任何该类的实例即可运行,而**非static的方法,在运行之前要先创建该类的实例对象**。 - -如何定义并调用一个非静态的方法 - -```c# -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } -``` - -### 3.方法的参数传递机制 - -​ 方法在Java中只有一个值传递,但是在C#中,可以有value(值传递),ref(引用传递)和out(输出传递) - -其中,ref和out使用效果上面是等效的,它们的区别在于:参数标记为ref,那么必须在调用函数之前初始化参数的值;参数标记为out,调用函数之前不需要初始化对象,但调用的函数必要在函数返回之前为对象赋值 - -```c# -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j) - { - j++; - } - - public static void OutFun(out int k) - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - int k; - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} - -``` - -### 4.方法的重载 - -重载:方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 - -```C# -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -//1.形参个数不同: 1和2 -//2.相同个数,形参类型不同:1,3,4 -//3.形参数据类型顺序不一致 -``` - -### 5.递归 - -​ 方法自己调用自己,递归2要素:①递归出口 ②递归表达式 - diff --git "a/47\345\267\253\346\231\250\347\276\277/\347\254\224\350\256\2603.md" "b/47\345\267\253\346\231\250\347\276\277/\347\254\224\350\256\2603.md" deleted file mode 100644 index 96ef6266a88a2550640c0315336e58b527f3faab..0000000000000000000000000000000000000000 --- "a/47\345\267\253\346\231\250\347\276\277/\347\254\224\350\256\2603.md" +++ /dev/null @@ -1,203 +0,0 @@ -# 笔记 - -***\*类与对像初识\**** - -***\*(1)面向对象的概念\**** - -面向对象:举个例子,盖一座大楼,你想到的是楼怎么盖,哪里要有珠子,哪里要有梁,哪里楼梯等等(这就是面向对象),至于柱子该怎么建,用什么建,方的圆的,等等,这就是面向过程。 - -用面向对象思考问题更符合我们人的思考方式。比如:去饭店吃饭,你只要说明吃什么就可以了,有必要还了解这个菜是怎么做的,是哪里来的,怎么去种这个菜吗? - -面向对象也可以说是从宏观方面思考问题,而面向过程可以说是从细节处思考问题。在面向对象中,也存在面向过程 - -***\*1.面向过程与对象的区别\**** - -面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一部一部实现,使用的时候一个一个一次调用就可以了 - - - -面向对象是把构成问题事务分解成各个对象,建立对象的目的不是为了完成一个步骤,而是为了描叙某个事物在整个解决问题的步骤中的行为 - -***\*2.深入理解对象\**** - -\1. 对象就是我们周围的各种各样的事物。 - -例如:衣服、杯子、宠物、朋友、电脑、汽车、电话等。 - -\2. 每个对象都有一些状态(属性)。 - -例如:衣服{颜色,长度,面料…}。 - -猫{名字,情绪,饥饿,}。 - -\3. 有些对象会作出一些行为。 - -例如:猫{发怒,玩耍,吃食,睡觉…}。 - -\4. 对象的行为会改变对象的状态。 - -例如:玩耍 → 疲劳=True 睡觉 → 疲劳=False 吃食 → 饥饿=False - -\5. 对象的状态会影响对象的行为。 - -例如:if( 饥饿 == False) → 吃食 return failure - - - ------- - - - -***\*(2)面向对象的语言\**** - -类 - -\1. 归纳共同点 - -\2. 具有相同数据和方法 - -\3. 是具有共同行为的若干个对象的统一描述体 - -对象 - -\1. 类的具体事物 - -\2. 类中方法的执行者 - -\3. 使用new创建 - - - ------- - - - -***\*==(3)类与对象的使用==\**** - -1.类的语法: - -​ [访问修饰符] ***\*class\**** 类名{ - - - -​ 字段;//描述对象的状态(声明变量) - - - -​ 方法;//实现对象的行为 - - - -​ 构造函数;//初始化对象 - - - - } - -2.实例化类 - -3.产生对象 - -4.使用对象 - - - ------- - - - -==(4)成员方法和构造方法== - -***\*1.成员方法\**** - -概念:类里面定义的方法 - -语法结构: - -[访问修饰符] 返回类型 <方法名> (参数列表) - - - -{ - - - - //方法体 - - - -} - -成员变量 - -方法调用 - -***\*==2.构造方法==\**** - -是类中的一种特殊的方法,构造函数名与类名相同,不返回任何值,可初始化成员变量 - -语法结构 - -[访问修饰符] <类名>()([参数列表]) - -{ - -​ //构造主体 - -} - -如果没有为类编写构造方法,系统自动生成无参数的构造方法,称为模式构造方法 - -a.无参构造方法 - -b.有参构造方法 - -构造方法可以更简捷的为对象赋初值,为对象开辟内存空间 - -例化对象时才能调用,This关键字,当前操作的对象 - -对象在创建的过程中有一个过程,当new的时候,会调用构造方法,在构造方法中可以做对象初始化操作 - -构造方法与成员方法不同,它是在对象创建时自动调用 - -构造方法可以有参数,也可以无参数 - -构造方法无返回值 - -构造方法名与类名相同 - -如果定义的类没有定义构造方法,对象在创建时默认使用空构造 - - - ------- - - - -***\*(5)总结\**** - -1.类 - -类是一种类型,反映了一些对象共同具有的数据和行为 - -对象是类具体的一个个体 - -2.成员方法 - -成员变量表示对象的特征, - -成员方法表示对象的行为 - -3.构造方法 - -如果类中未定义构造方法,则提供默认构造方法 - -构造方法分配成员变量所需内存空间,初始化成员变量 - -定义了有参构造方法后,应该添加无参构造方法 - -命名空间 - -用来组织类 - -namespace关键字 \ No newline at end of file diff --git "a/18\346\235\250\346\231\250\345\223\262/\347\254\224\350\256\260.md" "b/\345\220\264\346\230\212\347\273\251/\347\254\224\350\256\260.md" similarity index 77% rename from "18\346\235\250\346\231\250\345\223\262/\347\254\224\350\256\260.md" rename to "\345\220\264\346\230\212\347\273\251/\347\254\224\350\256\260.md" index ae68502ca371808fd30a347029f35957579e28b0..f90687c07e414b834f4c88d4d2b1aa06ad985bda 100644 --- "a/18\346\235\250\346\231\250\345\223\262/\347\254\224\350\256\260.md" +++ "b/\345\220\264\346\230\212\347\273\251/\347\254\224\350\256\260.md" @@ -331,6 +331,68 @@ public static void sum(double a,int b){}//4 构造方法分配成员变量所需内存空间,初始化成员变量 定义了有参构造方法后,应该添加无参构造方法 +静态方法与静态成员 +静态方法和静态成员变量是属于整个类的,不针对某个对象,所以它们是通过类来调用 +静态方法只能访问到静态成员变量,实例变量是访问不了的,也不能使用this关键字,因为this关键字表示正在操作的当前对象,静态的成员不能通过对象访问 +静态成员变量:类的成员变量被声明为static(称为静态成员变量),意味着它为该类的所有实例所共享,也就是说当某个类的实例修改了该静态成员变量,其修改值为该类的其它所有实例所见 + + +静态方法与实例方法区别 +使用static修饰的方法称为静态方法 +static 关键字 +使用类名调用 +可以访问静态成员 +不可以直接访问实例成员 +不能直接调用实例方法 +调用前初始化 + +使用实例对象调用的方法叫做实例方法 +不需要static关键字 +使用实例对象调用 +可以直接访问静态成员 +可以直接访问实例成员 +可以直接访问实例方法、静态方法 +实例化对象时初始化 + +属性 +#不能直接访问的数据 +通过访问器访问 +get 读 +set 写 +优点 +控制私有字段的可访问性 +保护内部数据安全性合法性 +根据属性读写的权限 +可读可写 +只读(省略set块) +只写(省略get块) + +索引器. +索引器是一种特殊的类成员 +允许按照数组的方式检索对象的数组元素 +索引器定义语法与属性定义语法类似 +索引器可以重载 +一个类可以有多个索引器 +没有静态索引器 + +语法 +[访问修饰符] 数据类型 this [数据类型 标识符] +{ +get{ … } +set{ … } +} + +委托 +委托是一个类 +将方法作为方法的参数 + +定义委托 +定义委托(指定委托名、委托将引用的方法的参数和返回值) +[访问修饰符] delegate 返回值类型 委托名([参数列表]) +实例化委托(将委托指向或引用某个方法,委托定义后必须实例化才能调用) +委托名 委托对象名= new 委托名(方法签名) +使用委托 +委托对象名([实参列表]) ## diff --git "a/\346\233\276\351\271\217/\344\275\234\344\270\232.md" "b/\346\233\276\351\271\217/\344\275\234\344\270\232.md" deleted file mode 100644 index e7a641fc26db6f1ad7369caea3f100d88327d429..0000000000000000000000000000000000000000 --- "a/\346\233\276\351\271\217/\344\275\234\344\270\232.md" +++ /dev/null @@ -1,15 +0,0 @@ -//第一题 using System; using System.Collections.Generic; using System.Text; - -namespace TSTS { class Student { //创建一个Student类,类中包含三个公共成员变量:stuName(学生姓名),stuAge(学生年龄),stuSex(学生性别),一个静态成员 变量tcAge(共青团员退团年龄),定义一个构造函数用于初始化学生姓名,学生年龄,学生性别,再定义一个无参构造函数,再定 义一个静态的方法SayHello(),输出学生的所有信息,实例化一个对象Mary public string stuName; public int stuAge; public char stuSex; public static int tcAge=25; //构造函数 public Student(string stuname,int stuage,char stusex) { this.stuName = stuname; this.stuAge = stuage; this.stuSex = stusex; } public static void SayHello(string stuname, int stuage, char stusex) { Console.WriteLine("姓名:{0},年龄:{1},性别:{2}",stuname,stuage,stusex); } //无参 public void student() { - - } } } //第二题 using System; using System.Collections.Generic; using System.Text; - -namespace TSTS { class Math { -//创建一个Math类,里边定义两个静态的方法,一个用于求两个数的和,另一个用于求三个数的和,方法名都定义成Add()(利用方法的重载) int a; int b; int c; //两个数的和 public static void add(int a,int b) { int sum = a + b; Console.WriteLine("两个数的和为:{0}",sum); } //三个数的和 public static void add(int a, int b, int c) { int sum = a + b + c; Console.WriteLine("三个数的和为:{0}", sum); } } } //第三题 using System; using System.Collections.Generic; using System.Text; - -namespace TEST { class Employee { #region 编写一个程序,用于计算三个职员的工资。 //第一位职员默认的基本工资为1000元 //第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 //第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。 //奖金应加到基本工资内(提示:创建一个Employee类,类中创建一个ComputeSalary()的方法, //为每个不同类别的职员重载该方法) - - //第一位职员默认的基本工资为1000元, public void ComputeSalary(int t) { Console.WriteLine("第一位职员的工资{0}", t); } //第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 public void ComputeSalary(int t, int a) { Console.WriteLine("请输入基本工资"); t = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入房租津贴"); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("第二位职员的工资{0}", t + a); } //第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。 public void ComputeSalary(int t, int a, int w) { Console.WriteLine("请输入是经理还是不是,是则有奖金收入"); string name = Console.ReadLine(); if (name.Equals("是")) { Console.WriteLine("请输入奖金"); w = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("经理的工资{0}", t + a + w); } else { Console.WriteLine("没有奖金!基本职员"); } } #endregion } } using System; - -namespace TSTS { class Program { static void Main(string[] args) { //第一题 Student a = new Student("张三", 28, '男'); a.student(); Console.WriteLine("姓名:{0}年龄:{1}性别:{2}",a.stuName,a.stuAge,a.stuSex); //第二题 Math.add(1, 20); Math.add(1, 3, 33); //第三题 Console.WriteLine("1是第一位职员、2是第二位职员、3是第三位职员"); Console.WriteLine("请输入一个数:"); int W = Convert.ToInt32(Console.ReadLine()); if (W == 1) { Employee a = new Employee(); a.ComputeSalary(1000); } else if (W == 2) { Employee a = new Employee(); a.ComputeSalary(0,0); } else if (W == 3) { Employee a = new Employee(); a.ComputeSalary(1000,500,0); } else { Console.WriteLine("输入错误,请重新输入!!!"); } } } } - diff --git "a/\346\233\276\351\271\217/\347\254\224\350\256\260.md" "b/\346\233\276\351\271\217/\347\254\224\350\256\260.md" deleted file mode 100644 index 87cb50966b49fe41463a3430ef1ab542041ec012..0000000000000000000000000000000000000000 --- "a/\346\233\276\351\271\217/\347\254\224\350\256\260.md" +++ /dev/null @@ -1,55 +0,0 @@ -C# 变量命名编码规范 小驼峰-首个单词的首字母小写,其余单词的首字母大写: 例如 int myName =ggg; 常用于变量,方法 - -大驼峰-所有单词首字母大写: 例如: public class DataBaseUser 常用于类名,属性,命名空间) - -字符串和数值型的互相转换 string myString = "Hello"; int myInt = int.Parse(myString); - -double score = 92.6; string myString = score.ToString( ); - -double score = 59.3; int myInt = Convert.ToInt32 (score); - -数据类型:byte,short,int,long,float,double,char,bool(布尔型),decimal(0,9) - -循环结构 四要素:1.初始值 2.判断条件 3.循环体 4.迭代因子 - -//while()循环 int i = 1; while (i<=10) { sum = sum + i;//sum+=i; i++; } Console.WriteLine(sum); //for()循环 int sum = 0; for (int i = 1; i <= 10; i++ ) { sum = sum + i;//sum+=i; } Console.WriteLine("和{0}", sum); - -随机数 - -int[] arr1 = new int[5]; Random rd = new Random(); for (int i = 0; i < arr1.Length; i++) { Arr[i] = rd.Next(0, 5); } foreach(var i in Arr1) { Console.Write(i+" "); } - -C#数组 - -设置初始化大小: int [ ] arr = new int[5]{0,1,2,3,4,}; int [ ] arr = new int [ ]{0,1,2,3,4,}; (省略长度) int [ ] arr = {0,1,2,3,4,}; (省略new) - -枚举 用于定义具有一组特定值的数据类型 枚举以enum关键字声明 enum student { 学生姓名 } - -foreach() 只读,不能修改。 引用类型 - -foreach(var i in arr1) { Console.WriteLine(i); } - -数组长度 数组名:length --------常作为循环条件 int[ ] array = new int[5] { 0, 1 ,2, 3, 4}; for (int i = 0; i < array.Length;i++ ) { Console.WriteLine(array[i]); } - -二维数组 - -int[,] arr = {{1,2,3},{4,5,6},{7,8,9}}; for (int i = 0; i < arr.GetLength(0); i++) { for (int j = 0; j < arr.GetLength(1); j++) { Console.WriteLine(arr[i, j]); } } - -枚举 - -public static void accu() { int sum = 0; for(int i = 1; i <= 10;i++) { sum += i; } } - -方法 ;访问修饰符 static 返回值类型 方法名() - -传递 ; 传递value(值传递)、ref(引用传递)、out(输出传递) - -方法重载:方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 - -访问修饰符:public(公共的),private(私有的),protected(受保护的),internal(内部的) static: 静态的 - -面向对象(三大特性):封装,继承,多态 - -**装箱** 就是把“值类型”转换成“引用类型”(Object); - -**拆箱** 就是把“引用类型”转换成“值类型”; - -int` `i=0; System.Object obj=i; Console.WriteLine(i+`","`+(`int`)obj); \ No newline at end of file diff --git "a/\346\261\237\345\230\211\345\205\264/4.7\347\254\224\350\256\260\344\275\234\344\270\232.md" "b/\346\261\237\345\230\211\345\205\264/4.7\347\254\224\350\256\260\344\275\234\344\270\232.md" deleted file mode 100644 index ff0fa3c59dca6e732f58c88ea847160f88ca26fd..0000000000000000000000000000000000000000 --- "a/\346\261\237\345\230\211\345\205\264/4.7\347\254\224\350\256\260\344\275\234\344\270\232.md" +++ /dev/null @@ -1,234 +0,0 @@ -## 笔记 - -装箱:将值类型--》引用类型 - -``` - int a = 5; //值类型 - Object obj = a; // 引用类型 - a = 6; - Console.WriteLine("obj={0}",obj); -``` - -​ 拆箱:将引用类型 --》值类型 - -```c# - - int b = (int)obj; - Console.WriteLine(b); -``` - -## 作业 - -一、 创建一个Student类,类中包含三个公共成员变量:stuName(学生姓名),stuAge(学生年龄),stuSex(学生性别),一个静态成员变量tcAge(共青团员退团年龄),定义一个构造函数用于初始化学生姓名,学生年龄,学生性别,再定义一个无参构造函数,再定义一个静态的方法SayHello(),输出学生的所有信息,实例化一个对象Mary - -```c# -using System; -using System.Collections.Generic; -using System.Text; - -namespace ConsoleApp2 -{ //创建一个Student类,类中包含三个公共成员变量: - //stuName(学生姓名),stuAge(学生年龄),stuSex(学生性别), - class Student - { - public string stuName; - public int stuAge; - public string stuSex; - static int tcAge=28; - //定义一个构造函数用于初始化学生姓名,学生年龄, - //学生性别,再定义一个无参构造函数,再定义一个静态的方法(), - public Student(string StuName, int StuAge, string StuSex) - { - this.stuName = StuName; - this.stuAge = StuAge; - this.stuSex = StuSex; - } - public Student() { } - public static void SayHello( string stuName, int stuAge, string stuSex, int tcAge) { - Console.WriteLine("名字是{1},年龄是{0}岁,性别是{2},退团年龄是{3}", stuAge, stuName, stuSex, tcAge); - - -} - - -​ - -} - -} -``` - -```c# -using System; - -namespace ConsoleApp2 -{ - - class or - { - - - //一个静态成员变量tcAge(共青团员退团年龄), - //定义一个构造函数用于初始化学生姓名,学生年龄, - //学生性别,再定义一个无参构造函数,再定义一个静态的方法SayHello(), - //输出学生的所有信息,实例化一个对象Mary - static void Main(string[] args) - { - Student h = new Student(); - Student.SayHello("mary", 18, "女",28); - - } - - - - } - -} - - -``` - - - - - -二、 创建一个Math类,里边定义两个静态的方法,一个用于求两个数的和,另一个用于求三个数的和,方法名都定义成Add()(利用方法的重载) - -```c# -using System; - -namespace ConsoleApp2 -{ - class Program - { - static void Main(string[] args) - { - int a = 2; - int b = 4; - int c = 6; - Add(a, b,c); - Add(a, b); - } - static void Add(int a,int b) - { - Console.WriteLine(a+b); - } - static void Add(int a, int b,int c) - { - Console.WriteLine(a+b+c); - } - } -} -``` - -三、 编写一个程序,用于计算三个职员的工资。第一位职员默认的基本工资为1000元,第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。奖金应加到基本工资内(提示:创建一个Employee类,类中创建一个ComputeSalary()的方法,为每个不同类别的职员重载该方法) - - - -~~~c# -using System; -using System.Collections.Generic; -using System.Text; - -namespace Text03 -{ - class Employee - { - // 三、 编写一个程序,用于计算三个职员的工资。第一位职员默认的基本工资为1000元, - // 第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 - // 第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。 - // 奖金应加到基本工资内(提示:创建一个Employee类,类中创建一个ComputeSalary()的方法, - // 为每个不同类别的职员重载该方法) - - -```c# - int a; -​ int b; -​ int c; - - public void ComputeSalary(int A) { - this.a = A; - - -​ - - } - - public void ComputeSalary(int A,int B) - { - this.a = A; - this.b = B; - - - } - public void ComputeSalary(int A, int B,int C) - { - this.a = A; - this.c = C; - - - } - } - -} - - -~~~ - - - -```c# -using System; - -namespace Text03 -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("请输入您是第几类员工"); - int m = Convert.ToInt32(Console.ReadLine()); - if (m == 1) - { - int a = 1000; - Console.WriteLine("您的工资为:"+ a); - } - else if (m == 2) - { - Console.WriteLine("输入基本工资"); - int a = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("输入住房补贴"); - int b = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("您的工资为:{0}",(a+b)); - - } - else - { - Console.WriteLine("是不是经理"); - string l = Convert.ToString(Console.ReadLine()); - if (l == "是") - { - Console.WriteLine("输入基本工资"); - int a = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("输入奖金"); - int c = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("您的工资为:{0}", (a + c)); - } - else if (l == "不是") { - Console.WriteLine("输入基本工资"); - int a = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("您的工资为:{0}", a ); - - } - } - Employee a1 = new Employee(); - Employee a2 = new Employee(); - Employee a3 = new Employee(); - - - } - } - -} -``` - diff --git "a/\346\261\237\345\230\211\345\205\264/C#\347\254\224\350\256\260.md" "b/\346\261\237\345\230\211\345\205\264/C#\347\254\224\350\256\260.md" deleted file mode 100644 index 41143fec3a95d15d8da34cff3ea73dfdf98fb2b8..0000000000000000000000000000000000000000 --- "a/\346\261\237\345\230\211\345\205\264/C#\347\254\224\350\256\260.md" +++ /dev/null @@ -1,414 +0,0 @@ -# - -## 1基本语法 - -### 1.数据类型 - -```c# -//整型:byte,short,int,long, -//浮点型:float,double,char -//布尔型: bool -//小数 : decimal(4,2) 4表示长度 , 2表示小数点后位数 -decimal a1 = 4.0m;//如果没有后缀 m,则数字将被视为 double 类型并会生成编译器错误。 - -``` - -### 2.运算符 : - -算术,比较,逻辑,三元 - -```c# - //算数:+ - * / % - //赋值运算:+=,-=,*=,/=,%= - //b += 1;// b= b+1, b++,++b - //比较运算符:>,<,>=,<=,!=,== - //bool b1 = b >= 7; - //逻辑:&&, ||, ! - //三元: (条件表达式A)?A为true:A为false - int a = 5; - int b = 8; - int c = 7; - int max = a > b ? (a>c?a:c) : (b>c?b:c); - Console.WriteLine(max); -``` - -### 3.输出 - -```c# -Console.Write(); //不换行 -Console.WriteLine("Hello World!"); //换行 - -``` - - - -### 4.输入 - -```c# -string a = Console.ReadLine();//默认输入的数据类型为string -Console.WriteLine(a); - -``` - - - -### 5.随机数 - -```c# - Random a = new Random(); -Random a = new Random();int[] ar = new int[10]; - - for (int I =0;I ar[i + 1] ? ar[i + 1] : MIN; - } - - Console.WriteLine(MAX+" "+MIN); -``` - - - -### 6.二维数组语句 - -```c# - -int[,] arr = { {1,2,3},{4,5,6},{7,8,9} }; - for (int i = 0; i < arr.GetLength(0); i++) - { - for (int j = 0; j < arr.GetLength(1); j++) - { - Console.WriteLine(arr[i, j]); - } - } - - //foreach - foreach (var i in arr) - { - Console.WriteLine(i); - } - - - - -``` - -#### 6.1获取数组长度 - -数组下标最大值 = 数组长度-1 - -```c# -int len = arr.Length; -int maxIdx = arr.Length - 1; -Console.WriteLine("数组arr的长度是:{0}",len); -Console.WriteLine("数组下标最大值:{0}",maxIdx); -``` - -### 7.枚举 - -```c# -namespace TEST02_1 -{ - class Program - { - enum student - { - 周飘, - 金星=10, - 曾鹏 - }; - -static void Main(string[] args) - { - - foreach (var i in Enum.GetValues(typeof(student))) - { - Console.WriteLine(i); - } -``` - - - -### 8.变量 - -```c# -//规则 -//组成:52个字母(A-Z, a-z),10个数字(0-9),下划线(_) -//开头:字母或下划线 -//不能是关键字 - - -int b = 6; -string c = "abc"; -var d = 5; -ar e = "abc"; -int(32位) short(16位) byte -//有符号,无符号 -//有符号 : short(-32,768到32,767之间的有符号整数值) -//无符号 : ushort(0到65,535之间的无符号整数值) -``` - - - -## 2.语句 - - - -### 1.选择结构 - -```c# -if(条件表达式1) -{ - 条件表达式1 为true,则执行 -}else if(条件表达式2) -{ - 条件表达式2 为true,则执行 -}else -{ - 上面都不执行则执行 -} -``` - -示例 - -```c# - int countChar = 0, countNumber = 0, countSym = 0; - Console.WriteLine("请输入一串字符:"); - string str = Console.ReadLine(); //fakghiag 4#&$#E - foreach (char j in str) - { - if (j >= 'A' && j <= 'Z' || j >= 'a' && j <= 'z') - //0 : 30; A: 41 ; a: 61 (参照ASCII 表) - { - countChar++; - } - else if (j >= '0' && j <= '9') - { - countNumber++; - } - else - { - countSym++; - } - } - - Console.WriteLine("数字{0},\t字母{1},\t特殊符号{2}\n", countNumber, countChar, countSym); - //Console.WriteLine("数字{countNumber},\t字母{countChar},\t特殊符号{countChar}\n"); - //转义字符必须在""中使用 -``` - - - -### 2.循环结构 - - 四要素:1.初始值 2.判断条件 3.循环体 4.迭代因子 - -#### 1.while 循环 - -```c# -//求 1+...+10 的和 - int i = 1; //初始值 - while (i<=10)//判断条件 - { - sum = sum + i;//循环体 - i++; //迭代因子 - } - Console.WriteLine(sum);//输出 -``` - -#### 2.for 循环 - -```c# -for(初始值;判断条件;迭代因子) -{ - 循环体 -} -``` - -#### 3.foreach循环 - -```c# -//用于列举出集合中所有的元素,foreach 语句中的表达式由关键字 in 隔开的两个项组成。 -//in 左边的项是变量名,in 右边的项是集合名,用来存放该集合中的每个元素。 -foreach(数据类型 变量名 in 数组名) 只读,不能修改。 引用类型 -{ - //语句块; Console.WriteLine(变量名) -} - - - foreach (var i in Enum.GetValues(typeof(student))) - { - Console.WriteLine(i); - } -``` - - - -## 3命名规范 - -```c# -//小驼峰 : 首个单词的首字母小写,其余单词的首字母大写 -//常用于变量,方法 -int myAge = 5; static void myClassInfo(); - -//大驼峰 : 所有单词首字母大写 -//用于类名,属性,命名空间 -public class DataBaseUser -``` - - - - - - - - - -## 4方法 - -### 1. 方法的作用 - -简化,重用代码。使得代码可读性强。 - -### 2.定义&调用方法 - -​ 定义方法 - -```c# -访问修饰符 static 返回值类型 方法名() -public static void accu() -{ - int sum = 0; - for(int i = 1; i <= 10;i++) - { - sum += i; - } -} -``` - -​ 定义相当于做好了一个工具,等待后面使用它。 - -​ 如何调用方法? - -```c# -public static void Main(String[] args) -{ - accu(); -} -``` - - - -主方法必须是static的,因为这个方法不能依赖任何该类的实例即可运行,而**非static的方法,在运行之前要先创建该类的实例对象**。 - -如何定义并调用一个非静态的方法 - -```c# -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } -``` - -### 3.方法的参数传递机制 - -​ 方法在Java中只有一个值传递,但是在C#中,可以有value(值传递),ref(引用传递)和out(输出传递) - -其中,ref和out使用效果上面是等效的,它们的区别在于:参数标记为ref,那么必须在调用函数之前初始化参数的值;参数标记为out,调用函数之前不需要初始化对象,但调用的函数必要在函数返回之前为对象赋值 - -```c# -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j) - { - j++; - } - - public static void OutFun(out int k) - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - int k; - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} - -``` - -### 4.方法的重载 - -重载:方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 - -```C# -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -//1.形参个数不同: 1和2 -//2.相同个数,形参类型不同:1,3,4 -//3.形参数据类型顺序不一致 -``` - -### diff --git "a/\346\261\237\345\230\211\345\205\264/C#\351\235\242\345\220\221\345\257\271\350\261\241\347\254\224\350\256\260.md" "b/\346\261\237\345\230\211\345\205\264/C#\351\235\242\345\220\221\345\257\271\350\261\241\347\254\224\350\256\260.md" deleted file mode 100644 index 4407424e9991fc92bd8917bb9bc721e5580b4a4f..0000000000000000000000000000000000000000 --- "a/\346\261\237\345\230\211\345\205\264/C#\351\235\242\345\220\221\345\257\271\350\261\241\347\254\224\350\256\260.md" +++ /dev/null @@ -1,113 +0,0 @@ -## 1.面向过程与对象的区别 - -面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一部一部实现,使用的时候一个一个一次调用就可以了面向对象是把构成问题事务分解成各个对象,建立对象的目的不是为了完成一个步骤,而是为了描叙某个事物在整个解决问题的步骤中的行为。 - -### 例子 - - 面向对象(三大特性):封装,继承,多态 - - Java,C#完全面向对象,C++(泛型) - 面向过程:C语言,C++ - 戴口罩--》出门--》下楼梯--》走路--》点菜--》付款--》脱口罩--》吃饭 - 面向对象:我要吃饭--》吃饭 - -1. 对象就是我们周围的具体的事物。 - -例如:衣服、杯子、宠物、朋友、电脑、汽车、电话等。 - -1. 每个对象都有一些状态(属性)。 - -例如:杯子{颜色,容量,材质…}。 - -## 二.语法 - -### 成员方法 - -概念:类里面定义的方法 - -语法结构: - -[访问修饰符] 返回类型 <方法名> (参数列表) - - - -{ - - - - //方法体 - - - -} - -### 构造方法 - -构造函数名与类名相同,不返回任何值,可初始化成员变量 - -[访问修饰符] <类名>()([参数列表]) - -{ - -​ //构造主体 - -} - -## 作业 - -```c# -namespace Text -{ - class Role - { - // 1.创建一个控制台应用程序,该程序名为ClassTest,在该程序中创建一个以Role为类名的、包含以下成员的一个类。 - public string Rolename; - public string gender; - public string provenance; - public string status; - public string fstatus; - public string lover; - public string father; - public string mother; - // 2、在ClassTest程序中,在Role类中定义一个该类的构造函数,实现给该类的字段赋值的功能 - public Role(string Name,string Gender,string Provenance,string Status, - string Fstatus,string Lover,string Father,string Mother) - { - this.Rolename = Name; - this.gender = Gender; - this.provenance = Provenance; - this.status = Status; - this.fstatus = Fstatus; - this.lover = Lover; - this.father = Father; - this.mother = Mother; - } - public void daxia() - { - Console.WriteLine("{0}是的{1}出自{2}是{3}和{4}爱侣是{5}父亲是{6}母亲是{7}",Rolename,gender,provenance,status,fstatus,lover,father,mother); - } - } -} -``` - - - -using System; - -namespace Text -{ - class or - { - - -```c# - static void Main(string[] args) - { - // 3、在ClassTest程序主函数中创建一个对象,并完成给该对象的成员赋以下的值并完成输出: - // 张无忌、男、倚天屠龙记、主角、明教教主、赵敏、张翠山、殷素素 - Role H = new Role("张无忌","男", "倚天屠龙记", "主角", "明教教主", "赵敏","张翠山","殷素素"); - H.daxia(); - } - } -} -``` diff --git "a/\346\261\237\345\230\211\345\205\264/\344\275\234\344\270\232.md" "b/\346\261\237\345\230\211\345\205\264/\344\275\234\344\270\232.md" deleted file mode 100644 index 57937ae9a060de527b39cde10e1950fa4f519723..0000000000000000000000000000000000000000 --- "a/\346\261\237\345\230\211\345\205\264/\344\275\234\344\270\232.md" +++ /dev/null @@ -1,55 +0,0 @@ -## 作业 - -1. 用户输入整数n,计算1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) - - - -```c# -using System; - -namespace ConsoleApp1 -{ - class Program - { - static void Main(string[] args) - { - int n = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine(Ic2(n)); - } -``` - - - -```C# - static int Ic(int n) - { - int ji = 1; - for (int a = 1; a <= n; a++) - { - ji = ji * a; - } - return ji; - } - static int Ic1(int n) - { - int sum = 0; - for (int a = 1; a <= n; a++) - { - sum += Ic(a); - } - return sum; - - } - static int Ic2(int n) - { - int count = 0; - for (int a = 1; a <= n; a++) - { - count = count + Ic1(a); - - } - return count; - } - } -} -``` \ No newline at end of file diff --git "a/\347\224\260\351\221\253\345\274\272/c#.md" "b/\347\224\260\351\221\253\345\274\272/c#.md" deleted file mode 100644 index ba22ebd62e751613cea15b271c3ebace95b493d3..0000000000000000000000000000000000000000 --- "a/\347\224\260\351\221\253\345\274\272/c#.md" +++ /dev/null @@ -1,842 +0,0 @@ -# 笔记 - -## 1 - -1. 输出 - - ```c# - Console.Write(); //不换行 - Console.WriteLine("Hello World!"); //换行 - - ``` - - - -2. 输入 - - ```c# - string a = Console.ReadLine();//默认输入的数据类型为string - Console.WriteLine(a); - - ``` - -3. 变量 - - ```c# - //规则 - //组成:52个字母(A-Z, a-z),10个数字(0-9),下划线(_) - //开头:字母或下划线 - //不能是关键字 - - - int b = 6; - string c = "abc"; - var d = 5; - ar e = "abc"; - int(32位) short(16位) byte - //有符号,无符号 - //有符号 : short(-32,768到32,767之间的有符号整数值) - //无符号 : ushort(0到65,535之间的无符号整数值) - ``` - - - -4. 常量 - - ```c# - const int e1 = 7; - ``` - -5. 数据类型 - - ```c# - //整型:byte,short,int,long, - //浮点型:float,double,char - //布尔型: bool - //小数 : decimal(4,2) 4表示长度 , 2表示小数点后位数 - decimal a1 = 4.0m;//如果没有后缀 m,则数字将被视为 double 类型并会生成编译器错误。 - - ``` - -6. 运算符 : 算术,比较,逻辑,三元 - - ```c# - //算数:+ - * / % - //赋值运算:+=,-=,*=,/=,%= - //b += 1;// b= b+1, b++,++b - //比较运算符:>,<,>=,<=,!=,== - //bool b1 = b >= 7; - //逻辑:&&, ||, ! - //三元: (条件表达式A)?A为true:A为false - int a = 5; - int b = 8; - int c = 7; - int max = a > b ? (a>c?a:c) : (b>c?b:c); - Console.WriteLine(max); - ``` - -7. 定义类型 - - ```c# - //输入一个int 数据类型 - int a1 = Convert.ToInt32(Console.ReadLine()); - ``` - - - -7. 选择结构 - - ```c# - if(条件表达式1) - { - 条件表达式1 为true,则执行 - }else if(条件表达式2) - { - 条件表达式2 为true,则执行 - }else - { - 上面都不执行则执行 - } - ``` - - - -8. 循环结构 四要素:1.初始值 2.判断条件 3.循环体 4.迭代因子 - - 1. while 循环 - - ```c# - //求 1+...+10 的和 - int i = 1; //初始值 - while (i<=10)//判断条件 - { - sum = sum + i;//循环体 - i++; //迭代因子 - } - Console.WriteLine(sum);//输出 - ``` - - 2. for 循环 - - ```c# - for(初始值;判断条件;迭代因子) - { - 循环体 - } - ``` - - 3. foreach循环 - - ```c# - //用于列举出集合中所有的元素,foreach 语句中的表达式由关键字 in 隔开的两个项组成。 - //in 左边的项是变量名,in 右边的项是集合名,用来存放该集合中的每个元素。 - foreach(数据类型 变量名 in 数组名) - { - //语句块; - } - ``` - - 示例 - - ```c# - int countChar = 0, countNumber = 0, countSym = 0; - Console.WriteLine("请输入一串字符:"); - string str = Console.ReadLine(); //fakghiag 4#&$#E - foreach (char j in str) - { - if (j >= 'A' && j <= 'Z' || j >= 'a' && j <= 'z') - //0 : 30; A: 41 ; a: 61 (参照ASCII 表) - { - countChar++; - } - else if (j >= '0' && j <= '9') - { - countNumber++; - } - else - { - countSym++; - } - } - - Console.WriteLine("数字{0},\t字母{1},\t特殊符号{2}\n", countNumber, countChar, countSym); - //Console.WriteLine($ "数字{countNumber},\t字母{countChar},\t特殊符号{countChar}\n"); - //转义字符必须在""中使用 - ``` - -9. 转义字符 - - | \n | 换行 | - | ---- | ---------------------------------------------- | - | \r | 回车 | - | \t | 制表符 | - | \f | 换页符 | - | \b | 退格 | - | \a | 响铃 | - | \e | escape(ASCII中的escape 字符) | - | \007 | 任何八进制值(这里是,007=bell(响铃)) | - | \x7f | 任何十六进制值(这里是,007=bell) | - | \cC | 一个控制符(这里是:Ctrl+c) | - | \l | 下个字符小写 | - | \L | 接着的字符均小写直到\E | - | \u | 下个字符大写 | - | \U | 接着的字符均大写直到\E | - | \Q | 在 non-word 字符前加上(自动加转义符号),直到\E | - | \E | 结束\L,\E和\Q | - | \0 | 空格 | - | | | - -## 2命名规范 - -```c# -//小驼峰 : 首个单词的首字母小写,其余单词的首字母大写 -//常用于变量,方法 -int myAge = 5; static void myClassInfo(); - -//大驼峰 : 所有单词首字母大写 -//用于类名,属性,命名空间 -public class DataBaseUser -``` - -## 3类型转换 - -```c# -1. -string myString = "Hello"; -int myInt = int.Parse(myString); -2. -double score = 92.6; -string myString = score.ToString( ); -3. -double score = 59.3; -int myInt = Convert.ToInt32 (score); - -``` - - - -## 4数组 - -### 1数组 - - - -```c# - int[] bub = { 8, 7, 4, 6, 5, 3 };//静态 - //外层for控制第几趟 - for(int i = 0; i < bub.Length; i++) - { - //每一趟找出最大往下沉 - for(int j = 0; j < bub.Length-1-i; j++) - { - if (bub[j] > bub[j + 1]) - { - int temp = bub[j]; - bub[j] = bub[j + 1]; - bub[j + 1] = temp; - } - } - } - foreach (var i in bub) - { - Console.WriteLine(i); - } - -``` - -### 2矩阵数组 - - 二维数组 同 多维数组 又称矩形数组 - -```c# -1. -int[,] myArray; - myArray = new int[2, 3];//2行 3列 - myArray[0, 0] = 1; - myArray[0, 1] = 2; - myArray[0, 2] = 3; - - - myArray[1, 0] = 4; - myArray[1, 1] = 5; - myArray[1, 2] = 6; - - - foreach (var item in myArray) - { - Console.WriteLine(item); - } - -2. -int[,] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; - - //for - for (int i = 0; i < arr.Getlength(0); i++) - { - for (int j = 0; j < arr.Getlength(1); j++) - - Console.Writeline(arr[i, j]); - } - } - - //foreach - foreach (var i in arr) - { - Console.Writeline(i); - } -``` - - - -## 5随机数 - - - -```c# -Random a = new Random();//产生随机数 -Console.WriteLine(a.Next(10)); //不包含10 -``` - -## 6枚举 - -```c# - enum student - { - 周飘, - 金星=10, - 曾鹏 - }; -//放在main 方法外 -``` - - - -## 7方法 - -### 1修饰符 - - - -访问修饰符:public(公共的),private(私有的),protected(受保护 - -的),internal(内部的) - -### 2调用非静态 - -```c# -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } -``` - - - -### 3传递 - -Java只有值传递,C#除此之外还有ref(引用)传递,out(输出)传递 - -值传递只能返回一个,ref,out可以返回多个值 - -value:实参和形参互相独立, 只进不出 - -ref:能改变实际参数的值, 又进又出 - -out : 只出不进 - -```c# -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j) - { - j++; - } - - public static void OutFun(out int k) - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - int k; - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} - -``` - - - -### 4重载和重写 - -1. 区别 - - 重载(overload)和重写(override)有什么区别 - 重载:方法名一样,但是:1.形参列表个数不一致;2.形参列表类型不一致;3.形参列表顺序不一致。 - -```c# -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -//1.形参个数不同: 1和2 -//2.相同个数,形参类型不同:1,3,4 -//3.形参数据类型顺序不一致 -``` - -### 5.递归 - -​ 方法自己调用自己,递归2要素:①递归出口 ②递归表达式 - - - -## 8面向对象 - -### 1 - -​ 面向对象(三大特性):封装,继承,多态, -​ Java,C#完全面向对象,C++(泛型) -​ 面向过程:C语言,C++ -​ 戴口罩--》出门--》下楼梯--》走路--》点菜--》付款--》脱口罩--》吃饭 - -​ 面向对象:我要吃饭--》吃饭 - -​ 类,万物皆对象 -​ 类:分类:人类(男人,女人,学生,歌手,演员),吉他,鸟类,肉类,海 鲜类 - -​ 对象:贺晋卓,黄楷钊, 愤怒的小鸟,燕子,麻雀, 鱼,虾(皮皮虾, 濑尿虾,小龙虾,大龙虾) - -### 2类与对象的使用 - -1. 类的语法: - -```c# -[访问修饰符] class 类名{ - - 字段;//描述对象的状态(声明变量) - - 方法;//实现对象的行为 - - 构造函数;//初始化对象 - - } -``` - -2. 实例化类 - -3. 产生对象 - -4. 使用对象 - -### 3成员方法和构造方法 - -1. 成员方法 - -​ 概念:类里面定义的方法 - -​ 语法结构: - -```c# -[访问修饰符] 返回类型 <方法名> (参数列表) - -{ - - //方法体 - -} -``` - -​ 成员变量 - -​ 方法调用 - -2. 构造方法 - - 是类中的一种特殊的方法,构造函数名与类名相同,不返回任何值,可初始化成员变量 - - 语法结构 - - ```c# - class Role - { - // 1、创建一个控制台应用程序,该程序名为ClassTest, - //在该程序中创建一个以Role为类名的、包含以下成员的一个类。 - //角色名、性别、出处、地位、门派地位、爱侣、父亲、母亲: - public string roleName; - public string gender; - public string provenance; - public string status; - public string fstatus; - public string lovepartner; - public string father; - public string mother; - - public Role(string RoleName, string Gender, string Provenance, - string Status, string Fstatus, string Lovepartner, string Father, string Mother) - { - this.roleName = RoleName; - this.gender = Gender; - this.provenance = Provenance; - this.status = Status; - this.fstatus = Fstatus; - this.lovepartner = Lovepartner; - this.father = Father; - this.mother = Mother; - } - public void plase() - { - Console.WriteLine("{0},{1}的,来自{2},很{3},是{4},爱侣是{5},父亲是{5},母亲是{6}", roleName, gender, provenance, status, fstatus, lovepartner, father,mother) ; - } - - } - ``` - - ```c# - Role H = new Role("林黛玉", "男", "北京", "高大上", "第一", "贾宝玉", "林某某", "贾某某"); - H.plase(); - Console.ReadLine(); - ``` - - - -3. 如果没有为类编写构造方法,系统自动生成无参数的构造方法,称为模式构造方法 - - a.无参构造方法 - - b.有参构造方法 - - 构造方法可以更简捷的为对象赋初值,为对象开辟内存空间 - - 例化对象时才能调用,This关键字,当前操作的对象 - - 对象在创建的过程中有一个过程,当new的时候,会调用构造方法,在构造方法中可以做对象初始化操作 - - 构造方法与成员方法不同,它是在对象创建时自动调用 - - 构造方法可以有参数,也可以无参数 - - 构造方法无返回值 - - 构造方法名与类名相同 - - 如果定义的类没有定义构造方法,对象在创建时默认使用空构造 - -## 9装箱和拆箱 - -//存与堆内存 -栈区:存放值类型的对象本身,引用类型的引用地址(指针), -静态区对象的引用地址(指针),常量区对象的引用地址(指针)等 -堆区:用于存放引用类型对象本身 - -```c# -//装箱和拆箱 -//装箱:将值类型转换为引用类型 -int value =9; -Object obj =value; -//拆箱:将引用类型转换为值类型 -int values=10; -Object obj =value; -int b=(int)Obj; -``` - - - -# 作业 - -## 1 - - - -//用户输入整数n,计算1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) - -```c# -static void Main(string[] args) - { - - Console.WriteLine("请输入整数n"); - int n = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine(jiSum(n)); - - } - static int jiSum(int n) - { - int jiSum = 0; - for (int a = 1; a <= n; a++) - { - jiSum += sum(a); - } - return jiSum; - } - - static int sum(int n) - { - int sum = 0; - for (int a = 1; a <= n; a++) - { - sum += ji(a); - } - return sum; - } - - - static int ji(int n) - { - int ji = 1; - for (int a=n;a>=1;a--) - { - ji *= a; - } - return ji; - } -``` - - -2. ``` - 1、创建一个控制台应用程序,该程序名为ClassTest,在该程序中创建一个以Role为类名的、包含以下成员的一个类。 - - 角色名、性别、出处、地位、门派地位、爱侣、父亲、母亲: - - 2、在ClassTest程序中,在Role类中定义一个该类的构造函数,实现给该类的字段赋值的功能。 - - 3、在ClassTest程序主函数中创建一个对象,并完成给该对象的成员赋以下的值并完成输出:张无忌、男、倚天屠龙记、主角、明教教主、赵敏、张翠山、殷素素 - - - ``` - - ```c# - class Role - { - public string name; - public string gander; - public string from; - public string status; - public string sectStatus; - public string lover; - public string father; - public string mother; - - public Role(string Name, string Gander, string From, string Status, - string SectStatus, string Lover, string Father, string Mother) - { - this.name = Name; - this.gander = Gander; - this.from = From; - this.status = Status; - this.sectStatus = SectStatus; - this.lover = Lover; - this.father = Father; - this.mother = Mother; - } - - public void intro() - { - Console.WriteLine($"{name}是{gander}生,是{from}的{status}{sectStatus},爱侣是{lover},父亲是{father},母亲是{mother}"); - } - } - - - - class Program - { - static void Main(string[] args) - { - Role i = new Role("张无忌","男","倚天屠龙记","主角","明教教主","赵敏","张翠山","殷素素"); - i.intro(); - } - } - ``` - - - -## 2 - -1. - -```c# -class Program - { - static void Main(string[] args) - { - //一、创建一个Student类,类中包含三个公共成员变量:stuName(学生姓名),stuAge(学生年龄),stuSex(学生性别), - //一个静态成员变量tcAge(共青团员退团年龄),定义一个构造函数用于初始化学生姓名,学生年龄,学生性别, - //再定义一个无参构造函数,再定义一个静态的方法SayHello(),输出学生的所有信息,实例化一个对象Mary - #region 1. - Student Mary = new Student(); - Student.SayHello("小明",19,"男"); - - #endregion - - - } - } - - - -class Student - { - public string stuName;//(学生姓名) - public int stuAge;//(学生年龄) - public string stuSex;//(学生性别) - public static int tcAge=28;//(共青团员退团年龄) - - public Student(string StuName,int StuAge,string StuSex) - { - this.stuName = StuName; - this.stuAge = StuAge; - this.stuSex = StuSex; - } - public Student() - { - - } - public static void SayHello(string StuName, int StuAge, string StuSex) - { - Console.WriteLine("学生姓名为:{0}\t年龄为:{1}\t性别为{2}:\t共青团员退团年龄:{3}",StuName,StuAge,StuSex,tcAge); - } - - } - -``` - -2. - - ```c# - class Program - { - static void Main(string[] args) - { - //二、创建一个Math类,里边定义两个静态的方法,一个用于求两个数的和, - //另一个用于求三个数的和,方法名都定义成Add()(利用方法的重载) - #region 2 - int a = 1; - int b = 2; - int c = 3; - Math.Add(a, b); - Math.Add(a, b, c); - - #endregion - - } - } - - class Math - { - - public static void Add(int a,int b) - { - Console.WriteLine(a+b); - } - public static void Add(int a,int b,int c) - { - Console.WriteLine(a + b + c); - - } - } - ``` - - 3. - - ```c# - class Program - { - static void Main(string[] args) - { - //三、编写一个程序,用于计算三个职员的工资。第一位职员默认的基本工资为1000元, - //第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 - //第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。奖金应加到基本工资内 - //(提示:创建一个Employee类,类中创建一个ComputeSalary()的方法, - //为每个不同类别的职员重载该方法) - - #region 3 - Console.WriteLine("请问你是第几位职员") ; - int m = Convert.ToInt32(Console.ReadLine()); - if (m==1) - { - Employee.ComputeSalary(); - } - else if (m==2) - { - - Console.WriteLine("请输入您的基本工资"); - int a = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("请输入您的住房津贴"); - int b = Convert.ToInt32(Console.ReadLine()); - Employee.ComputeSalary(a, b); - - } - else - { - Console.WriteLine("您是经理吗(yes/no)"); - string a = Console.ReadLine(); - if (a == "yes") - { - Console.Write("请输入您的的基本工资:"); - int b = Convert.ToInt32(Console.ReadLine()); - Console.Write("请输入您的奖金:"); - int c = Convert.ToInt32(Console.ReadLine()); - Employee.ComputeSalary(a, b, c); - - } - else - { - Console.Write("请输入您的的基本工资:"); - int b = Convert.ToInt32(Console.ReadLine()); - int c = 0; - Employee.ComputeSalary(a, b, c); - - } - } - #endregion - - - - } - } - - class Employee - { - - public static void ComputeSalary() - { - int a = 1000; - Console.WriteLine("你的基本工资为:"+a); - } - public static void ComputeSalary(int a,int b) - { - Console.WriteLine("你的总工资为:" + (a + b)); - } - public static void ComputeSalary(string a,int b,int c) - { - Console.WriteLine("你的总工资为:" + (b + c)); - } - } - ``` - - diff --git "a/\350\214\203\351\233\205\346\254\242/03\344\275\234\344\270\232.md" "b/\350\214\203\351\233\205\346\254\242/03\344\275\234\344\270\232.md" deleted file mode 100644 index c88608c620e75c1b9c247f0224fadbbe6f07239f..0000000000000000000000000000000000000000 --- "a/\350\214\203\351\233\205\346\254\242/03\344\275\234\344\270\232.md" +++ /dev/null @@ -1,21 +0,0 @@ -```c# -using System; -namespace ConsoleApp4 -{class Program - {static void Main(string[] args) - {//11.用户输入整数n,计算1! + (1! + 2!) + (1! + 2! + 3!) - //+…..+(1! + 2! +…n!) - int i, j=1, m = 0, sum = 0; - Console.WriteLine("请输入一个整数"); - int n = Convert.ToInt32(Console.ReadLine()); - for (i = 1; i <= n; i++) - { - j*= i; - m += j; - sum += m; - } - Console.WriteLine(sum); } - } -} -``` - diff --git "a/\350\214\203\351\233\205\346\254\242/04\344\275\234\344\270\232.md" "b/\350\214\203\351\233\205\346\254\242/04\344\275\234\344\270\232.md" deleted file mode 100644 index 29ba999028802ea766098f08d010bbd664b13c7e..0000000000000000000000000000000000000000 --- "a/\350\214\203\351\233\205\346\254\242/04\344\275\234\344\270\232.md" +++ /dev/null @@ -1,100 +0,0 @@ -###### 第一题 - -```c# -using System; - -namespace classtest -{ - class Role - {//角色名、性别、出处、地位、门派地位、爱侣、父亲、母亲: - //张无忌、男、倚天屠龙记、主角、明教教主、赵敏、张翠山、殷素素 - public string rname; - public string gender; - public string from; - public string status; - public string ustatus; - public string lover; - public string father; - public string mother; - - public Role() - { - } - - public Role(string Rname, string Gender, string From, string Status, string Ustatus, - string Lover, string Father, string Mother) { - this.rname= Rname; - this.gender = Gender; - this.from = From; - this.status = Status; - this.ustatus = Ustatus; - this.lover = Lover; - this.father = Father; - this.mother = Mother; - - } - public void shuchu() - { - Console.WriteLine("我是{0},性别{1},来自{2},是{3},在门派中我是{4},爱人是{5},父亲是{6},母亲是{7}",rname,gender,from,status,ustatus,lover,father,mother); - } - } - -} - -using System; -using System.Collections.Generic; -using System.Text; - -namespace classtest -{ - - class role1 - { - static void Main(string[] args) - { - Role ro = new Role("张无忌", "男", "倚天屠龙记", "主角", - " 明教教主", "赵敏", "张翠山", "殷素素"); - ro.Shuchu(); - } - } -} -``` - -###### 第二题 - -```c# -using System; - -namespace ConsoleApp1 -{ - class account - { - public decimal balance; - public account() { balance = 1000; } - public account(decimal Balance) - { - this.balance = Balance; - } - public decimal smoney; - public decimal dmoney; - - public account(decimal Smoney,decimal Dmoney,decimal Balance) - { this.balance= Balance; - this.dmoney = Dmoney; - this.smoney = Smoney; - }public void zuih() { Console.WriteLine("你需要查询余额{0},还是存钱{1},又或是取钱{2}", balance, smoney, dmoney); } - }class c02 - { - static void Main(string[] args) - { - account ac = new account(); - ac.zuih(); - - } - - } - } - - -``` - diff --git "a/\350\276\276\345\205\264\345\273\272/\344\275\234\344\270\232.md.md" "b/\350\276\276\345\205\264\345\273\272/\344\275\234\344\270\232.md.md" deleted file mode 100644 index 18e6f935b25d4cbfeafc120f3f320fdcbd848734..0000000000000000000000000000000000000000 --- "a/\350\276\276\345\205\264\345\273\272/\344\275\234\344\270\232.md.md" +++ /dev/null @@ -1,150 +0,0 @@ - - -using System; -using System.Collections.Generic; -using System.Text; - -namespace TSTS -{ - class Student - { - 1创建一个Student类,类中包含三个公共成员变量:stuName(学生姓名),stuAge(学生年龄),stuSex(学生性别),一个静态成员 变量tcAge(共青团员退团年龄),定义一个构造函数用于初始化学生姓名,学生年龄,学生性别,再定义一个无参构造函数,再定 义一个静态的方法SayHello(),输出学生的所有信息,实例化一个对象Mary - public string stuName; - public int stuAge; - public char stuSex; - public static int tcAge=25; - 构造函数 - public Student(string stuname,int stuage,char stusex) - { - this.stuName = stuname; - this.stuAge = stuage; - this.stuSex = stusex; - } - public static void SayHello(string stuname, int stuage, char stusex) - { - Console.WriteLine("姓名:{0},年龄:{1},性别:{2}",stuname,stuage,stusex); - } - - -​ public void student() -​ { - -​ } -​ } -} -2 -using System; -using System.Collections.Generic; -using System.Text; - -namespace TSTS -{ - class Math - { - 创建一个Math类,里边定义两个静态的方法,一个用于求两个数的和,另一个用于求三个数的 和,方法名都定义成Add()(利用方法的重载) - int a; - int b; - int c; - public static void add(int a,int b) - { - int sum = a + b; - Console.WriteLine("两个数的和为:{0}",sum); - } - -​ public static void add(int a, int b, int c) -​ { -​ int sum = a + b + c; -​ Console.WriteLine("三个数的和为:{0}", sum); -​ } -​ } -} -3 -using System; -using System.Collections.Generic; -using System.Text; - -namespace TEST -{ - class Employee - { - #region 编写一个程序,用于计算三个职员的工资。 - 第一位职员默认的基本工资为1000元 - 第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 - 第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。 - 奖金应加到基本工资内(提示:创建一个Employee类,类中创建一个ComputeSalary()的方法, - 为每个不同类别的职员重载该方法) - -​ 第一位职员默认的基本工资为1000元, -​ public void ComputeSalary(int t) -​ { -​ Console.WriteLine("第一位职员的工资{0}", t); -​ } -​ 第二位职员除具有基本工资外,还具有住房津贴。接受用户输入的基本工资和住房津贴。 -​ public void ComputeSalary(int t, int a) -​ { -​ Console.WriteLine("请输入基本工资"); -​ t = Convert.ToInt32(Console.ReadLine()); -​ Console.WriteLine("请输入房租津贴"); -​ a = Convert.ToInt32(Console.ReadLine()); -​ Console.WriteLine("第二位职员的工资{0}", t + a); -​ } -​ 第三位职员可能是经理也可能不是,如果是,则有奖金收入,应接受输入的奖金值。 -​ public void ComputeSalary(int t, int a, int w) -​ { -​ Console.WriteLine("请输入是经理还是不是,是则有奖金收入"); -​ string name = Console.ReadLine(); -​ if (name.Equals("是")) -​ { -​ Console.WriteLine("请输入奖金"); -​ w = Convert.ToInt32(Console.ReadLine()); -​ Console.WriteLine("经理的工资{0}", t + a + w); -​ } -​ else -​ { -​ Console.WriteLine("没有奖金!基本职员"); -​ } -​ } -​ #endregion -​ } -} - using System; - -namespace TSTS -{ - class Program - { - static void Main(string[] args) - { - 1 - Student a = new Student("张三", 28, '男'); - a.student(); - Console.WriteLine("姓名:{0}年龄:{1}性别:{2}",a.stuName,a.stuAge,a.stuSex); - 2 - Math.add(1, 20); - Math.add(1, 3, 33); - 3 - Console.WriteLine("1是第一位职员、2是第二位职员、3是第三位职员"); - Console.WriteLine("请输入一个数:"); - int W = Convert.ToInt32(Console.ReadLine()); - if (W == 1) - { - Employee a = new Employee(); - a.ComputeSalary(1000); - } - else if (W == 2) - { - Employee a = new Employee(); - a.ComputeSalary(0,0); - } - else if (W == 3) - { - Employee a = new Employee(); - a.ComputeSalary(1000,500,0); } - else - { - Console.WriteLine("输入错误,请重新输入!!!"); - } - } - } -} - diff --git "a/\350\276\276\345\205\264\345\273\272/\347\254\224\350\256\260.md.md" "b/\350\276\276\345\205\264\345\273\272/\347\254\224\350\256\260.md.md" deleted file mode 100644 index d579257801ece07789e523100f4d1a9cf5e4856c..0000000000000000000000000000000000000000 --- "a/\350\276\276\345\205\264\345\273\272/\347\254\224\350\256\260.md.md" +++ /dev/null @@ -1,338 +0,0 @@ -——输出 - -Console.WriteLine("Hello World!");//println -Console.Write();//print - -——输入 - -string a = Console.ReadLine(); -Console.WriteLine(a); - -——变量const int a = 7; - -——数据类型: - -byte,short,int,long,float,double,char,bool(布尔型),decimal(0,9) - -——赋值运算:+=,-=,*=,/=,%= //运算符: //算数:+ - * / % //比较:>,<,>=,<=,!=,== //逻辑:&&,||,! ——三元:(条件表达式A)?A为True:A为False - -int a = 5; -int b = 8; -int c = 7; -int max = a > b ? (a>c?a:c) : (b>c?b:c); -Console.WriteLine(max); - -——输出数组中的最大最小值 -Random a = new Random(); -int[] ar = new int[10]; -for (int I =0;I ar[i + 1] ? ar[i + 1] : MIN; -} -Console.WriteLine(MAX+" "+MIN); - -将一个数组中的元素逆序输出,即第一个元素和最后一个元素交换, -第二个数与倒数第二元素交换…..,例如:原数组为:9 2 5 7 8, -逆序后的数组为:8 7 5 2 9 -int[] arr2 = new int[5]; -for(int i = 0; i < arr2.Length; i++) -{ -arr2[i] = Convert.ToInt32(Console.ReadLine()); -} -逆序前 -Console.WriteLine("逆序前:"); -foreach (var i in arr2) -{ - Console.WriteLine(i); -} -逆序 -9 2 5 7 8 -8 2 5 7 9 -8 7 5 2 9 -8 7 5 2 9 -int t; -for(int i = 0; i < arr2.Length/2; i++) -{ - t = arr2[i]; - arr2[i] = arr2[arr2.Length - 1-i]; - arr2[arr2.Length - 1 - i] = t; -} -Console.WriteLine("逆序后:"); -foreach (var i in arr2) -{ - Console.WriteLine(i); -} -bubble -int[] bub = { 8, 7, 4, 6, 5, 3 }; -外层for控制第几趟 -for(int i = 0; i < bub.Length; i++) -{/每一趟找出最大往下沉 - for(int j = 0; j < bub.Length-1-i; j++) - { - if (bub[j] > bub[j + 1]) - { - int temp = bub[j]; - bub[j] = bub[j + 1]; - bub[j + 1] = temp; - } - } -} -foreach (var i in bub) -{ - Console.WriteLine(i); -} - -枚举 - -using System; - -namespace TEST02_1 -{ - -class Program -{ - enum name - { - 第一, - 第二, - 第三 - }; - -——方法 - -定义方法:访问修饰符 static 返回值类型 方法名() -public static void accu() -{ - int sum = 0; - for(int i = 1; i <= 10;i++) - { - sum += i; - } -} -——调用方法 - public static void Main(String[] args) -{ - accu(); -} -——定义并调用一个非静态的方法 -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } - -传递value(值传递)、ref(引用传递)、out(输出传递) - -using System; - -——value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - -​ public static void RefFun(ref int j) -​ { -​ j++; -​ } - -​ public static void OutFun(out int k) -​ { -​ k = 0;使用out关键字,必须参数初始化 -​ k++; -​ } - -​ static void Main() -​ { -​ int i = 0; -​ ValueFun(i);//i的值是实参的一个副本,实参i不会改变 -​ Console.WriteLine(i); - -​ int j = 0; -​ RefFun(ref j);指向同一块内存,实参j的值会改变 -​ Console.WriteLine(j); - -​ int k; -​ OutFun(out k);和ref关键字等效 -​ Console.WriteLine(k); -​ } -} - -方法的重载重载: - -方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} -public static void sum(int a, double b){} -public static void sum(double a,int b){} -class Person - { - 老贺 属性.行为(19,男,长得很帅,声音好听,大长腿 - 唱,跳,rap,篮球,玩CSGO,吹牛,看妞,学习) - public string name; - public int age; - public string gender; //性别 - public double height; // - public double weight; - public string nation; - public string hobby; - public string skin; - ——行为 - -​ ——构造方法:初始化成员变量 -​ public Person(string Name, int Age, string Gender, double Height, -​ double Weight, string Nation, string Hobby, string Skin) -​ { -​ this.hobby = Hobby; -​ this.name = Name; -​ this.age = Age; -​ this.gender = Gender; -​ this.height = Height; -​ this.weight = Weight; -​ this.nation = Nation; -​ this.skin = Skin; - -​ } -​ -​ private void walk() //私有的:private:当前类里边使用 -​ { -​ Console.WriteLine("走路"); -​ } - -​ public void eat() //公共的:所有地方都能用 -​ { -​ Console.WriteLine("{0}岁的,{3}皮的,{4}的,{5}的,在吃饭,等下要去{2}", age, name, hobby, skin, height, weight); -​ } - -​ } -program.cs - static void Main(string[] args) -​ { -​ 面向对象(三大特性):封装,继承,多态, -​ Java,C#完全面向对象,C++(泛型) -​ 面向过程:C语言,C++ -​ -​ 实例化 -​ Person p = new Person("老贺", 19, "男", 178, 65,"中国", "看妞", "黄"); -​ p.name = "老贺"; -​ p.age = 19; -​ p.gender = "男"; -​ p.hobby = "看妞"; -​ p.skin = "黄"; -​ p.height = 178; -​ p.weight = 65; -​ p.nation = "中国"; -​ p.eat(); -​ Console.ReadLine(); - -​ Role H = new Role("林黛玉", "男", "北京", "高大上", "第一", "贾宝玉", "林某某", "贾某某"); -​ H.plase(); -​ Console.ReadLine(); -​ 程序 = 算法(算法导论)+数据结构(面向对象) -​ ——11. 用户输入整数n,计算1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) -​ 1.n! -​ 2.(1!+2!+…n!) = fact(1)+fact(2)..+fact(n-1)+fact(n) -​ 1 + 2+3 +4+...+n -​ 3.1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) -​ umFact(1)+sumFact()+...+sumFact(n) -​ static int fact(int n) -​ { -​ int ji = 1; -​ for(int i = 1; i <= n; i++) -​ { -​ ji *= i; -​ 累乘 -​ } -​ return ji; -​ } - -​ 2.(1!+2!+…n!) = fact(1)+fact(2)..+fact(n-1)+fact(n) -​ 累加 -​ static int sumFact(int n) -​ { -​ int sum = 0; -​ for(int i = 1; i <= n; i++) -​ { -​ sum += fact(i); -​ } -​ return sum; -​ } - -​ sumFact(1)+sumFact()+...+sumFact(n) -​ static void sumFcat1(int n) -​ { -​ int sum = 0; -​ for(int i = 1; i <= n; i++) -​ { -​ sum += sumFact(i); -​ } -​ } - } -——值类型:表示实际数据 接存储值 据存储在堆栈中 nt、char,结构stuct -简单类型: -有符号整型:int long short sbyte -无符号整型:uint ulong ushort usbyte -字符类型:char -浮点型:float double decimal -布尔型:bool -枚举:enum -结构体类型:struct -——引用类型:数据存储在堆中 存储数据的地址 类、数组、字符串 -类:基类:System.Object 字符串:String 自定义类:class -接口:interface -数组:int[] string[] -值类型与引用类型的区别 -​ 值类型: -​ 1.内存分配: -​ 值类型总会分配到变量被声名的地方 -​ 声名的是局部变量,将被分配到栈上 -​ 声名为引用类型成员时,则被分配到托管堆上 -​ 2.赋值方式: -​ 复制变量包含的值 -​ 3.基类 -​ 值类型继承自Sysetem.ValueType-->System.ValueType又继承自System.Object -​ 引用类型: -​ 1.内存分配: -​ 实例总是分配到托管堆上 -​ 变量存储在栈中,因为变量只是实例数据的一个引用。可理解为一个地址 -​ 2.赋值方式: -​ //复制对象的引用,即对象的地址 -​ 3.基类 -​ //引用类型继承自System.Object -——存与堆内存 -栈区:存放值类型的对象本身,引用类型的引用地址(指针), -静态区对象的引用地址(指针),常量区对象的引用地址(指针)等 -堆区:用于存放引用类型对象本身 -——装箱和拆箱 -装箱:将值类型转换为引用类型 -int value =9; -Object obj =value; -拆箱:将引用类型转换为值类型 -int values=10; -Object obj =value; -int b=(int)Obj; \ No newline at end of file diff --git "a/\350\276\276\345\205\264\345\273\272/\347\254\224\350\256\2601.md.md" "b/\350\276\276\345\205\264\345\273\272/\347\254\224\350\256\2601.md.md" deleted file mode 100644 index 89ae54c609f58a4480e05323c6f1babfe675c7bb..0000000000000000000000000000000000000000 --- "a/\350\276\276\345\205\264\345\273\272/\347\254\224\350\256\2601.md.md" +++ /dev/null @@ -1,79 +0,0 @@ - 变量命名规则: C# 变量命名编码规范——Camel 命名法: - -​ 小驼峰-首个单词的首字母小写,其余单词的首字母大写: - -​ 例如 int myAge = 5; static void myClassInfo( ) 常用于变量,方法 - -​ 大驼峰-所有单词首字母大写: - -​ 例如: public class DataBaseUser 常用于类名,属性,命名空间) - - 字符串和数值型的互相转换 string myString = "Hello"; int myInt = int.Parse(myString); - -​ double score = 92.6; -​ string myString = score.ToString( ); - -​ double score = 59.3; -​ int myInt = Convert.ToInt32 (score); - -数据类型: byte,short,int,long,float,double,char,bool(布尔型),decimal(0,9) - -循环结构 四要素:1.初始值 2.判断条件 3.循环体 4.迭代因子 - -​ while()循环 -​ int i = 1; -​ while (i<=10) -​ { -​ sum = sum + i;//sum+=i; -​ i++; -​ } -​ Console.WriteLine(sum); -​ for()循环 -​ int sum = 0; -​ for (int i = 1; i <= 10; i++ ) -​ { -​ sum = sum + i;//sum+=i; -​ } -​ Console.WriteLine("和{0}", sum); - -随机数: - -​ int[] arr1 = new int[5]; -​ Random rd = new Random(); -​ for (int i = 0; i < arr1.Length; i++) -​ { -​ Arr[i] = rd.Next(0, 5); -​ } -​ foreach(var i in Arr1) -​ { -​ Console.Write(i+" "); -​ } - -C#数组 设置初始化大小: int [ ] arr = new int[5]{0,1,2,3,4,}; -int [ ] arr = new int [ ]{0,1,2,3,4,}; (省略长度) int [ ] arr = {0,1,2,3,4,}; (省略new) - -枚举 用于定义具有一组特定值的数据类型 枚举以enum关键字声明 enum student { 学生姓名 } - - foreach() 只读,不能修改。 引用类型 - -​ foreach(var i in arr1) -​ { -​ Console.WriteLine(i); -​ } - -数组长度 数组名:length --------常作为循环条件 - - int[ ] array = new int[5] { 0, 1 ,2, 3, 4}; -for (int i = 0; i < array.Length;i++ ) -{ Console.WriteLine(array[i]); } - -二维数组 - -​ int[,] arr = {{1,2,3},{4,5,6},{7,8,9}}; -​ for (int i = 0; i < arr.GetLength(0); i++) -​ { -​ for (int j = 0; j < arr.GetLength(1); j++) -​ { -​ Console.WriteLine(arr[i, j]); -​ } -​ \ No newline at end of file diff --git "a/\351\231\210\346\236\253/.keep" "b/\351\231\210\346\236\253/.keep" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/\351\231\210\346\236\253/3.31c#\347\254\224\350\256\260.md" "b/\351\231\210\346\236\253/3.31c#\347\254\224\350\256\260.md" deleted file mode 100644 index e587e81e98effef628b39820d63ae097225a3454..0000000000000000000000000000000000000000 --- "a/\351\231\210\346\236\253/3.31c#\347\254\224\350\256\260.md" +++ /dev/null @@ -1,202 +0,0 @@ -# C#3.31笔记 - -# 变量命名规则: - -## 组成: - -52个字母(A-Z, a-z),10个数字(0-9),下划线(_) - -## 开头: - -字母或下划线 - -不能是关键字 - -# C# 变量命名编码规范——Camel 命名法: - -## 小驼峰 - --首个单词的首字母小写,其余单词的首字母大写。 - -例如 - -```c# - int myAge = 5; static void myClassInfo( ) -``` - -常用于变量,方法 - -## 大驼峰 - --所有单词首字母大写: - -例如 - -```c# -public class DataBaseUser -``` - -常用于类名,属性,命名空间 - -# 初始化 - -```c# -switch (int / char / string表达式) -{ - case 常量表达式1: - 语句1; - break; //必须有 - case 常量表达式2: - 语句2; - break; //必须有 - …… - default: - 语句n; - break; //必须有 -} -``` - -# 类型转换 - -**string myString = "Hello";** - -**int myInt = int.Parse(myString);** - -**double score = 92.6;** - -**string myString = score.ToString( );** - -**double score = 59.3;** - -**int myInt = Convert.ToInt32 (score);** - -# **数组** - -## **数组基础** - -### 初始化 - -**int**[ ] arr1; - -**//**数据类型[ ]数组名; - -**int** **arr1[ ];** - -**//**数据类型 数组名[ ]; - -#### **如何设置大小及初始化?** - -**//** **使用** **new** **设置大小** - -**//** **创建长度为**5的整型数组 - -**int**[ ] array =** **new** **int****[5]; - -**//** **创建的同时初始化** - -**int**[ **] arr** **=** **new** **int**[5]{0,1,2,3,4}; - -**int**[ **] arr** **=** **new** **int**[ **]{0,1,2,3,4};** **//** 省略长度 - -**int**[ **] arr** **=** **{0,1,2,3,4};** **//** **省略**new - -**[5]——**方括号中的数字决定数组的长度 - -**{0,1,2,3,4}——**大括号中的元素个数决定数组的长度 - -## 数组长度 - -### 遍历&赋值 - -**数组名**.Length - -**常作为循环的条件** - -**//** **循环打印数组元素** - -** - -```c# -int[ ] array = new int[5] { 0, 1 ,2, 3, 4}; //声明并初始化一维数组 - -for (int i = 0; i> int number=2009; - -string [ ]strs=new string[ ]{“2008”,“2009”,“80”“20”}; - -userinfo ui= new UserInfo(); -``` - -**使用:** - -第一**范围**,可以在声明局部变量时使用,for语句中,foreach语句中,using语句中; - -第二**原则**:必须包含一个初始化器;声明的变量初始化值不能为null;不能同一语句初始化多个隐式类型变量。 - -# foreach遍**语法:** - -foreach (数据类型 元素(变量) **in** 集合或者数组) - -{ - - //语句 - -}历 - -### 枚举 - -用于定义具有一组特定值的数据类型 - -枚举以 enum 关键字声明 - -enum weekday - -{ - -Sun, - -Mon, - -Tue, - -Wed, - -Thu, - -Fri, - -Sat - -} - -遍历枚举元素 - -```c# -Foreach(var i in Enum.GetValues(typeof(weekday))) - -{ - -Console.WriteLine(i); - -} -``` - diff --git "a/\351\231\210\346\236\253/\346\225\260\347\273\204\345\222\214\346\226\271\346\263\225.md" "b/\351\231\210\346\236\253/\346\225\260\347\273\204\345\222\214\346\226\271\346\263\225.md" deleted file mode 100644 index e819878985fb3cff97239c2acbe283cd42d0ecb3..0000000000000000000000000000000000000000 --- "a/\351\231\210\346\236\253/\346\225\260\347\273\204\345\222\214\346\226\271\346\263\225.md" +++ /dev/null @@ -1,243 +0,0 @@ -## 一、数组与枚举 - -### 1.什么是数组 - -数组是一个**有序的元素序列**,如果将有限个类型相同的变量的集合命名,那么这个名称就是数组名,而组成数组的各个变量称为数组的分量,也称为数组的元素,有时也称为下标变量。 - -### 2.声明并初始化数组 - -#### 2.1数组声明 - -```C# -int[] arr;//声明 -arr = new int[5];//初始化 -``` - -![](F:\C#\笔记\image-20220331104116586.png) - -#### 2.2数组初始化 - -```c# -//1.静态初始化:给定数组长度和元素 -//与Java中不同的是,int arr[]在C#中将变得不可用 -int[] arr = new int[]{1,3,5,6,7}; //int[] arr = {1,3,5,6,7}; -var arr = new string[]{"1","2","3"};//var arr = {"1","2","3"}; - -//2.动态初始化:给定数组长度,但是元素不赋值 -int[] arr = new int[5]; -var arr = new int[5]; -``` - -### 3.数组动态赋值与遍历 - -#### 3.1数组赋值 - -数组如果不赋值,将会有默认值,其中,int型数组默认值是0,浮点型默认值是0.0,bool默认值是false,string默认值是null,其它引用类型默认值也是null。 - -```c# -var arr = new int[5]; -//一个个赋值 -arr[0] = 0; -arr[1] = 1; -arr[2] = 2; -arr[3] = 3; -arr[4] = 4; -//利用循环赋值 -for(int i = 0; i<5;i++) -{ - arr[i] = i-1; -} -``` - -#### 3.2获取数组长度 - -数组下标最大值 = 数组长度-1 - -```c# -int len = arr.Length; -int maxIdx = arr.Length - 1; -Console.WriteLine("数组arr的长度是:{0}",len); -Console.WriteLine("数组下标最大值:{0}",maxIdx); -``` - -#### 3.3遍历数组元素 - -**for遍历** - -```c# -for(int i = 0; i< arr.Length;i++) -{ - Console.Write(arr[i]+" "); -} -``` - -**foreach遍历** - -```c# -foreach(var i in arr) -{ - Console.Write(i+" "); -} -``` - -### 4.矩阵数组 - -矩阵数组也称为多维数组 - -#### 4.1二维数组 - -```c# -//静态初始化 -int[,] arr = new int{{1,2,3,4},{5,6,7,8},{9,10,11,12}}; -// -int[][] arr = new int[5][]; -int[,] arr2 = new int[3,3]; -``` - - - - - -C#中,我们在创建二维数组的时候,一般使用arr[][]的形式,例如 - -int[][] aInt = new int[2][]; - -但声明二维数组还有一种方法,是使用arr[,]的形式。两者有什么区别呢? - - - -实际上,形如arr[,]只能声明等长的二维数组,例如 - -int[,] ab1 = new int [2,3];//默认值为0; int[,] ab2 = new int[2,3]{{1,2,3},{4,5,6}}; - - - -形如arr[][]的形式则可以声明等长二维数组,也可以声明不等长二维数组。例如 - -int [][] abc = new int[2][]; abc[0] = new int[]{1,2}; abc[1] = new int[]{3,4,5,6}; - - - -C#的不规则二维数组可以理解为 保存一维数组的数组 - - - -## 二、方法 - -### 1. 方法的作用 - -简化,重用代码。使得代码可读性强。 - -### 2.定义&调用方法 - -​ 定义方法 - -```c# -访问修饰符 static 返回值类型 方法名() -public static void accu() -{ - int sum = 0; - for(int i = 1; i <= 10;i++) - { - sum += i; - } -} -``` - -​ 定义相当于做好了一个工具,等待后面使用它。 - -​ 如何调用方法? - -```c# -public static void Main(String[] args) -{ - accu(); -} -``` - -![image-20220330174424816](C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220330174424816.png) - -主方法必须是static的,因为这个方法不能依赖任何该类的实例即可运行,而**非static的方法,在运行之前要先创建该类的实例对象**。 - -如何定义并调用一个非静态的方法 - -```c# -class Program - { - public static void Main(string[] args) - { - Program p = new Program(); - p.hi(); - } - public extern void hi() - { - Console.Write("Hello C#"); - } - } -``` - -### 3.方法的参数传递机制 - -​ 方法在Java中只有一个值传递,但是在C#中,可以有value(值传递),ref(引用传递)和out(输出传递) - -其中,ref和out使用效果上面是等效的,它们的区别在于:参数标记为ref,那么必须在调用函数之前初始化参数的值;参数标记为out,调用函数之前不需要初始化对象,但调用的函数必要在函数返回之前为对象赋值 - -```c# - -using System; - -//value(值传递)、ref(引用传递)、out(输出传递) -public class Test -{ - public static void ValueFun(int i) - { - i++; - } - - public static void RefFun(ref int j) - { - j++; - } - - public static void OutFun(out int k) - { - k = 0;//使用out关键字,必须参数初始化 - k++; - } - - static void Main() - { - int i = 0; - ValueFun(i);//i的值是实参的一个副本,实参i不会改变 - Console.WriteLine(i); - - int j = 0; - RefFun(ref j);//指向同一块内存,实参j的值会改变 - Console.WriteLine(j); - - int k; - OutFun(out k);//和ref关键字等效 - Console.WriteLine(k); - } -} - -``` - -### 4.方法的重载 - -重载:方法名相同,但是①形参个数不同;②相同个数,形参类型不同;③形参数据类型顺序不一致。 - -```C# -public static void sum(int a, int b){} //1 -public static void sum(int a, int b, int c){} //2 -public static void sum(int a, double b){} //3 -public static void sum(double a,int b){}//4 -//1.形参个数不同: 1和2 -//2.相同个数,形参类型不同:1,3,4 -//3.形参数据类型顺序不一致 -``` - -### 5.递归 - -​ 方法自己调用自己,递归2要素:①递归出口 ②递归表达式 -