我需要把它变成一个数组列表而不是一个数组,我不知道如何开始。程序接受一个文件并逐行读取文件,并检查每个unque字符出现的次数。
class Program
{
static void Main(string[] args)
{
// Parse arguments.
if (args.Length != 2)
{
Console.WriteLine("Two arguments are needed.");
return;
}
var inputFile = args[0];
var outputFile = args[1];
var asciiTable = new charfrequency[255];
var input = File.ReadAllLines(inputFile);
var output = "";
Console.WriteLine(string.Format("The input file is: <{0}>.", inputFile));
Console.WriteLine(string.Format("The output file is: <{0}>.", outputFile));
// creates the asci table.
for (var i = 0; i < asciiTable.Length; i++)
{
asciiTable[i] = new charfrequency();
asciiTable[i].setCharacter((char)i);
}
// Parse the file line by line.
foreach (var line in input)
{
foreach (var character in line)
{
var key = (int)character;
if (key < 255 && key >= 0)
{
asciiTable[key].increment();
}
}
}
// Write to the output string.
foreach (var charfrequency in asciiTable)
{
if (charfrequency.getFrequency() > 0)
{
output += charfrequency.toString();
//string.Format("{0}[{1}]: {2}{3}", charfrequency.getCharacter(), (int)charfrequency.getCharacter(), charfrequency.getFrequency(), Environment.NewLine);
}
}
// Write the output string to the outputFile.
File.WriteAllText(outputFile, output);
}