C# Can';我的类中没有访问方法

C# Can';我的类中没有访问方法,c#,class,namespaces,C#,Class,Namespaces,我有一个关于文本文件的小班: using System.IO; namespace My_Application { public static class FileIO { public static void WriteText(string filename, string text) { StreamWriter file = new StreamWriter(filename); file

我有一个关于文本文件的小班:

using System.IO;

namespace My_Application
{
    public static class FileIO
    {
        public static void WriteText(string filename, string text)
        {
            StreamWriter file = new StreamWriter(filename);
            file.Write(text);
            file.Close();
        }

        public static string ReadText(string filename)
        {
            StreamReader file = new StreamReader(filename);
            string text = file.ReadToEnd();
            file.Close();

            return text;
        }
    }
}
我的主文件:

using System;
using System.Windows.Forms;

namespace My_Application
{
    public partial class Form1 : Form
    {    
        public Form1()
        {
            InitializeComponent();
        }

        private string readTestFile()
        {
            // error is here:

            return FileIO.ReadFile("test.txt");
        }
    }
}
我收到错误消息:

My_Application.FileIO'不包含'ReadFile'的定义

这很奇怪,因为我在另一个应用程序中使用了这个类,它工作了。 我发现的唯一区别是,另一个应用程序只有一个单词名,没有“\u1”

以后编辑/添加:

嗯。我的问题是方法名不好。然而,这仍然很奇怪,因为当我编写
FileIO.
(我还试着按ctrl-space)时,IntelliSense没有任何提示


附加问题:为什么IntelliSense没有看到这些方法?

您的方法被称为
ReadText
,但您正在尝试调用
ReadFile

声明:

public static string ReadText(string filename)
使用方法:

return FileIO.ReadFile("test.txt");
不应该这样

return FileIO.ReadFile("test.txt");
应该是

return FileIO.ReadText("test.txt");

在您的示例中,该方法称为ReadText,您将其引用为ReadFile。您知道File.ReadAllText/File.WriteAllText吗?(另外:您当前的代码缺少必要的dispose调用,通常通过“使用”完成)这是我在stackoverflow上问的最愚蠢的问题:)但是这很奇怪-当我编写
FileIO时。
intellisense没有任何建议。为什么?我的建议是:在提问之前尝试使用VisualStudioIntelliSense。这很琐碎,没有必要问它。@pt12lol我正在使用IntelliSense,但是。。。正如我在上面所写的,它没有任何暗示。这很奇怪…留下评论不是更好吗?因为它很简单:你是对的。此外,在我重新启动Visual Studio之前,我的智能感知已经中断。