我在控制台应用程序中编写了一个程序.我在命令行中上传文本文件时遇到问题.如果我放置直接路径"string s = File.ReadAllText("E:/Aspdot.txt");" 像这样在编程它的工作正常.但是,我希望在运行时上传或提及路径作为commanline输入.
在这里,我正在放置我的踪迹......任何人都可以建议我怎么做......
class Program
{
static void Main()
{
// 1.
// Array to store occurances.
int[] c = new int[(int)char.MaxValue];
// 2.
// Read entire text file.
Console.WriteLine("Please enter your text file path");
String a = Console.ReadLine();
//string s = File.ReadAllText("E:/Aspdot.txt");
string s = File.ReadAllText(a);
// 3.
// Iterate over each character.
foreach (char t in s)
{
// Increment table.
c[(int)t]++;
}
// 4.
// Write all letters found.
for (int i = 0; …Run Code Online (Sandbox Code Playgroud) 我想写一个问题从命令行读取文本文件并输出每个唯一字母的计数,按字母顺序排序.在C#中对此程序的任何建议示例:
堆栈溢出
输出:
a 1 c 1 k 1 t 1 s 2
c# ×2