1 using System; 2 using System.IO; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace UsefulProject 9 { 10 public class Program 11 { 12 static string line; 13 static int linesnum; 14 15 static void Main(string[] args) 16 { 17 ReviseFileContent(@"D:\mylist.txt"); 18 19 Console.WriteLine(linesnum); 20 Console.ReadKey(); 21 } 22 23 public static void ReviseFileContent(string path) 24 { 25 StreamReader sr = new StreamReader(@"D:\list.txt", Encoding.Default); 26 StreamWriter sw = new StreamWriter(@"D:\mylist.txt"); 27 28 while (true) 29 { 30 if ((line = sr.ReadLine()) != null) 31 { 32 string[] ss = line.Split(‘.‘); 33 string s = ss[0].ToString() + "S." + ss[1].ToString(); 34 35 sw.WriteLine(s); 36 37 linesnum++; 38 } 39 } 40 41 sw.Close(); 42 sr.Close(); 43 44 } 45 } 46 }
奇怪的是linesnum在控制台显示不出来了,如果将函数ReviseFileContent注释掉,可以正常显示,不想了吃饭去……
时间: 2024-10-09 22:57:08