C# 列表中的问题

C# 列表中的问题,c#,C#,我有一个字符串[]的问题,我想做一个编程语言。如果你知道好的编译器设计教程和C语言的例子,那就太好了 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; class Program { static void Main() { StreamReader reader = new StreamReader("C:

我有一个字符串[]的问题,我想做一个编程语言。如果你知道好的编译器设计教程和C语言的例子,那就太好了

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Program
{
    static void Main()
    {
        StreamReader reader = new StreamReader("C:/tut.txt");
        String data = reader.ReadLine();

        String[] tok;

        foreach(char s in data)
        {
            Console.WriteLine(s);
            tok.add(s); // error
        }

        Console.ReadKey();
    }
}

我不太确定你想要完成什么…也许是这个

        StreamReader reader = new StreamReader("C:/tut.txt");
        String data = reader.ReadLine();

        List<String> tok = new List<string>();

        foreach (char s in data)
        {
            Console.WriteLine(s);
            tok.Add(s.ToString());
        }
StreamReader=newstreamreader(“C:/tut.txt”);
字符串数据=reader.ReadLine();
List tok=新列表();
foreach(数据中的字符)
{
控制台。写入线(s);
tok.Add(s.ToString());
}

Ahem,问题是?
String[]
是数组而不是动态列表。如果您需要一个列表,请将其定义为
list tok
第一小节第4项:要求我们推荐或查找书籍、工具、软件库、教程或其他非现场资源的问题不属于堆栈溢出的主题,因为它们往往会吸引自以为是的答案和垃圾邮件。相反,请描述问题以及迄今为止为解决它所做的工作。@Tigran您还需要实例化它
List tok=new List()
您可以阅读Niklaus Wirth(微型)的书,作为编译器构造理论和技术的介绍。它让您大致了解编译器是什么以及它的功能。我还想看看编辑者编辑者。是一个.NET编译器,允许您使用C#构造定义语言的语法!似乎
tok
作为
列表会更好