自动生成C#中的单词列表,并另存为文件

自动生成C#中的单词列表,并另存为文件,c#,string,file,ascii,auto-generate,C#,String,File,Ascii,Auto Generate,我需要帮助编写接受单个参数的方法long I: public static string GetWord(long i) { string s = ""; //Update s using i return s; } …对于我保存ASCII字文件的程序 public static void main(string[] args) { try { int First = int.Parse(args[0]); int

我需要帮助编写接受单个参数的方法
long I

public static string GetWord(long i)
{
    string s = "";

    //Update s using i

    return s;
}
…对于我保存ASCII字文件的程序

public static void main(string[] args) 
{
    try
    {
        int First = int.Parse(args[0]);
        int Last = int.Parse(args[1])
        string Filename = args[2]

        for(int i = start; i <= end; i++)
             File.AppendLine(Filename, GetWord(i));

        Console.WriteLine("Process complete");

    } 
    catch(Exception ex)
    {
        Console.WriteLine(ex.Message);

    }

}
publicstaticvoidmain(字符串[]args)
{
尝试
{
int First=int.Parse(args[0]);
int Last=int.Parse(args[1])
字符串文件名=args[2]

对于(inti=start;i我只给你算法

请注意,每256是一个循环。从索引256开始,您将追加到
Word[0],
从512开始,您将追加到
Word[1]
,从65536开始,您将追加到
Word[0]+Word[0]
,即
Word[256]


因此,算法是将
索引/256-1
作为要附加到的索引,
索引%256
将作为需要附加的字节

我提出的解决方案如下:

public void AppendFile(string filePath, long firstWord, long lastWord)
{            
    using (StreamWriter sw = File.AppendText(filePath))
    {
        for (long i = firstWord; i < lastWord; i++)
        {
            sw.WriteLine(GetWord(i));

        }

    }

}

public void AppendFile(string filePath, long lastWord)
{
    AppendFile(filePath, 0, lastWord);

}

public void AppendFile(string filePath)
{
    AppendFile(filePath, long.MaxValue);

}

public static string GetWord(long i)
{
    string s = Encoding.ASCII.GetString(new byte[] { (byte)(i % 128) });

    if (i < 128)
        return s;

    return GetWord(i / 128) + s;

}
注意:我选择不使用Steve的答案中的算法。我不使用Steve算法的原因是,在整个过程中,他依赖于驻留在内存中的完整单词数组,这将输出文件限制在可用RAM的数量内。我的版本没有此限制,仅限于max字符串的可能长度


因此,您希望方法中的参数类型为long,以循环直到该数字生成单词?作为具有3.3k rep的用户,您应该知道“我需要一个方法”不是请求帮助,而是请求解决方案:-)我投票以离题的方式结束这个问题,因为,正如你们所做的那样,我有一种方法可以做到这一点,但不幸的是,我把它忘在出租车里了。那时我还年轻得多。这个算法是如何产生的,混合了记忆和欲望……我的观点是,我们强制用户分享他们的尝试,这样我们就可以帮助他们解决问题,而不是填鸭式的他们想要的:-)顺便说一句,我的评论没有恶意。注意:单词[128]到单词[255]都将是“?”。
AppendFile("words.txt"); // Will most likely fall over or at least take a long time

AppendFile("words.txt", 1000); // This is the method requested

AppendFile("words.txt", 500, 1000); // Extended functionality