1
我需要將其作爲數組列表而不是數組,並且我不知道如何啓動。該程序將獲取一個文件並逐行讀取文件,並檢查每個不可識別字符出現的次數。將數組代碼轉換爲數組列表C#
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);
}
任何你想使用'ArrayList'而不是'List'的原因? –