用了VS,现学了一波C#,感觉和JAVA差不多。与是就用C#把单词统计的程序写了一下。
废话不多说,先上代码。
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace Text_Screen 8 { 9 /** 10 * 用于统计文档中的字符,单词,以及行数 11 */ 12 class CharStatistics 13 { 14 private int charCount; //用于记录字符数 15 private int wordCount; //用于记录单词数 16 private int lineCount; //用于记录行数 17 18 public CharStatistics() { 19 this.SetChar(0); 20 this.SetWord(0); 21 this.SetLine(0); 22 } 23 24 public void IncreaseChar() 25 { 26 this.charCount++; 27 } 28 29 public void IncreaseWord() 30 { 31 this.wordCount++; 32 } 33 34 public void IncreaseLine() 35 { 36 this.lineCount++; 37 } 38 39 public void SetChar(int charCount) 40 { 41 this.charCount = charCount; 42 } 43 44 public void SetWord(int wordCount) 45 { 46 this.wordCount = wordCount; 47 } 48 49 public void SetLine(int LineCount) 50 { 51 this.lineCount = LineCount; 52 } 53 54 public int GetChar() 55 { 56 return this.charCount; 57 } 58 59 public String ToString() 60 { 61 String a = null; 62 a = "字符数:" + this.charCount + "\n单词数:" + this.wordCount + "\n行数:" + this.lineCount; 63 return a; 64 } 65 } 66 }