⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filedetails.cs

📁 csharp-solution,C#高效编程源码
💻 CS
字号:

using System;                // Console
using System.IO;             // FileStream, FileReader
    
class FileDetails 
{
    static void Main(string[] args) 
	{
        string fileName = args[0];
        FileStream stream = new FileStream(fileName, FileMode.Open);
        StreamReader reader = new StreamReader(stream); 
        int size = (int)stream.Length;
        char[] contents = new char[size];
        for (int i = 0; i < size; i++) {
            contents[i] = (char)reader.Read();
        }
        reader.Close();
        Summarize(contents);
    }

    static void Summarize(char[] contents) 
	{
        int vowels = 0, consonants = 0, lines = 0;
        foreach (char current in contents) {
            if (Char.IsLetter(current)) {
                if ("AEIOUaeiou".IndexOf(current) != -1) {
                    vowels++;
                } else {
                    consonants++;
                }
            }
            else if (current == '\n') {
                lines++;
            }
        }
        Console.WriteLine("Total no of characters: {0}", contents.Length);
        Console.WriteLine("Total no of vowels    : {0}", vowels);
        Console.WriteLine("Total no of consonants: {0}", consonants);
        Console.WriteLine("Total no of lines     : {0}", lines);            
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -