From 377d782d4ff233310a4a09485ffd2259e87e986d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=96=E6=9D=B0=E6=9E=97?= <2890111060@qq.com> Date: Tue, 17 May 2022 19:24:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../C#\344\275\234\344\270\232.md" | 120 +++++++++++++++++- 1 file changed, 118 insertions(+), 2 deletions(-) diff --git "a/46\350\265\226\346\235\260\346\236\227/C#\344\275\234\344\270\232.md" "b/46\350\265\226\346\235\260\346\236\227/C#\344\275\234\344\270\232.md" index 6b91a08..4a2596a 100644 --- "a/46\350\265\226\346\235\260\346\236\227/C#\344\275\234\344\270\232.md" +++ "b/46\350\265\226\346\235\260\346\236\227/C#\344\275\234\344\270\232.md" @@ -440,7 +440,7 @@ class Program } ``` -# 集合作业1 +# 集合作业 ``` 1. @@ -566,5 +566,121 @@ class Employee } ``` -# 集合2 +# 5.6作业 +```c# +//1. 定义两个存放(int)的集合,集合listA {“a”,”b”,”c”,”d”,”e”} listB {“d”,”e”,”f”,”g”,”h”}, //将这两个集合去除重复项后合并成一个集合。 Contains + + List listA = new List() {"a","b","c","d","e" }; + List listB = new List() {"d","e","f","g","h"}; + for (int i = 0; i < listB.Count; i++) + { + if (!listA.Contains(listB[i])) + { + listA.Add(listB[i]); + } + + } + Console.WriteLine(string.Join(" ",listA)); + +//2.简繁转换 +namespace 简繁转换 +{ + class Program + { + private const string alb = "123456"; + private const string ftz = "壹贰叁肆伍陆"; + static void Main(string[] args) + { + Hashtable w = new Hashtable(); + + for (int i = 0; i < alb.Length; i++) + { + w.Add(alb[i], ftz[i]); + } + Console.WriteLine("请输入:"); + string w1 = Console.ReadLine(); + for (int i = 0; i < w1.Length; i++) + { + if (ht.ContainsKey(w1[i])) + { + Console.WriteLine(w[w1[i]]); + } + else + { + Console.WriteLine(w1[i]); + } + } + Console.ReadKey(); + } +} + +} +``` + + + +# 5.10作业 + +``` +namespace zuoye +{ + class Program + { + static void Main(string[] args) + { + //1.在桌面创建名为:Demo 的文件夹,并添加两个子文件夹:TEST1 和 TEST2 + //2.在TEST2中创建test2.txt文件并复制到TEST1.test1中 + //3.使用流在test1写入StreamWriter写入数据: 道阻且难,行则将至。 + //4.使用流在test2写入StreamWriter写入数据: 不忘初心,方得始终。 + //5.在控制台输出这两句话。 + //1.创建文件夹 + string path = @"C:\Users\Administrator\Desktop\Demo"; + //Directory.CreateDirectory(path); + //2.添加子文件夹 + //string path1 = @"C:\Users\Administrator\Desktop\Demo\TEST1"; + // Directory.CreateDirectory(path1); + //string path2 = @"C:\Users\Administrator\Desktop\Demo\TEST2"; + // Directory.CreateDirectory(path2); + //3.创建test2文件 + //File.Create(path2+@"\test2.txt"); + //4.复制到TEST1中 + string test1 = @"C:\Users\Administrator\Desktop\Demo\TEST1\test1.txt"; + string test2 = @"C:\Users\Administrator\Desktop\Demo\TEST2\test2.txt"; + //File.Copy(test2,@"C:\Users\Administrator\Desktop\Demo\TEST1\test1.txt"); + + //5.创建文件流 + FileStream fs1 = new FileStream + (test1,FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None); + FileStream fs2 = new FileStream + (test2,FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None); + //6.创建写入对象 + StreamWriter s1 = new StreamWriter(fs1); + StreamWriter s2 = new StreamWriter(fs2); + //7.写入 + s1.WriteLine("道阻且难,行则将至。"); + s2.WriteLine("不忘初心,方得始终。"); + //8.关闭流 + s2.Close(); + s1.Close(); + //9.读 + FileStream fs11 = new FileStream + (test1, FileMode.Open,FileAccess.Read,FileShare.None); + FileStream fs22 = new FileStream + (test2, FileMode.Open, FileAccess.Read, FileShare.None); + + StreamReader d1 = new StreamReader(fs11); + StreamReader d2 = new StreamReader(fs22); + //10.读到控制台 + Console.WriteLine("结果:{0}",sr1.ReadToEnd()); + Console.WriteLine("结果:{0}", sr2.ReadToEnd()) ; + fs1.Close(); + fs2.Close(); + d1.Close(); + d2.Close(); + Console.WriteLine("完成"); + } +} + +} +``` -- Gitee