c#我的getter不是';行不通

c#我的getter不是';行不通,c#,C#,我试图在VisualStudio中为我的类编写一个字谜分析器,但是当我从另一个类调用getter时,我的列表是空的 public class UserInput { private String fileName; private string text; private string[] words; private List<string> preparedWord = new List<string>(); Regex reg

我试图在VisualStudio中为我的类编写一个字谜分析器,但是当我从另一个类调用getter时,我的列表是空的

public class UserInput
{
    private String fileName;
    private string text;
    private string[] words;
    private List<string> preparedWord = new List<string>();
    Regex reg = new Regex(@"(\s-|[^A-Za-z0-9])");
    private string t = "testing";

    public void promptFile()
    {
        Console.WriteLine("Enter a .txt file");
        this.fileName = Console.ReadLine();
        this.fileConversion();
        this.wordSeperator();

       // foreach (string word in this.preparedWord)
        //{
          //  System.Console.WriteLine(word);
        //}

        //{
        //    System.Console.WriteLine(this.preparedWord.Count);
        //}
    }

    public String getFileName
    {
        get { return this.t; }
    }

    private void fileConversion()
    {
         StreamReader streamReader = new StreamReader(this.fileName);
        this.text = streamReader.ReadToEnd();
        streamReader.Close();
        Console.WriteLine(text);
    }

    public void wordSeperator()
    {
        this.words = text.Split(' ', ',', '.', ':','\t');

        foreach (string s in words)
        {
            this.preparedWord.Add(reg.Replace(s, ""));// @"\W\S", ""));
        }
    }

    public List<string> getPreparedList{
         get
         {
              return this.preparedWord;}
         } 
}
}
当我调用方法让它写单词时,它是空的,并且它说计数是0。当我在UserInput类中编写列表时,一切都是应该的


关于为什么会发生这种情况,有什么建议吗?

当您从AnagramManager类实例化UserInput类时,您从未向其分配任何内容。您使用:

UserInput u = new UserInput();

然后你有一个空的类实例。您需要定义一个构造函数来将一些数据放入其中,或者从Anagramanager中填充它。

@Smac89-不,他做对了您确定调用了
WordSeparator()
?它只被
promptFile()
调用,而没有被任何东西调用。@music\u coder很抱歉,我忘了用调用promptFile()的main方法粘贴该类。但是是的,它被称为。我很难相信这一点,否则你就不会有问题了。这实际上是一个使用调试器的好机会。在
promptFile()。对不起,我是c的新手#
UserInput u = new UserInput();