C# Can';不要使用公共静态类或don';我不知道怎么做

C# Can';不要使用公共静态类或don';我不知道怎么做,c#,static,C#,Static,我有一个公共静态类出纳: namespace MPP_TCP_Client { public static class Cashier { public static IPAddress localAddr = IPAddress.Parse("127.0.0.1"); public static TcpClient Connect() { try {

我有一个公共静态类
出纳

namespace MPP_TCP_Client
{
    public static class Cashier
    {
        public static IPAddress localAddr = IPAddress.Parse("127.0.0.1");

        public static TcpClient Connect()
        {
            try
            {
                return new TcpClient(Util.localAddrStr, Util.port);
            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine("ArgumentNullException: {0}", ane);
            }
            catch (SocketException se)
            {
                Console.WriteLine("SocketException: {0}", se);
            }
            catch (NullReferenceException nre)
            {
                Console.WriteLine("Null Reference Exception: {0}", nre);
            }
            return null;
        }

        // etc.
    }
}
现在我想使用
Connect
方法:

namespace Mpp_TCP_Client
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press enter to start client");
            Console.ReadKey();
            TcpClient whatever = Cashier.Connect(); // Cashier is not being seen by Visual Studio
        }
    }
}
正如Dennis_E在上面提到的(我在发布这个答案后注意到了他的评论):

您的名称空间有不同的大小写

Cashier
类使用:
MPP\u TCP\u客户端
程序
类使用:
MPP\u TCP\u客户端

尝试以下与名称空间匹配的方法:

namespace MPP_TCP_Client // This should now be the same as the Cashier class
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press enter to start client");
            Console.ReadKey();
            TcpClient whatever = Cashier.Connect(); // Cashier is not being seen by Visual     Studio
        }
    }
}
或者,如果这是有意的,请添加以下using语句:

using MPP_TCP_Client;

名称空间不同吗?或者它只是一个输入错误?第一个名称空间称为“MPP_TCP_客户端”,第二个名称空间称为“MPP_TCP_客户端”,不,不是。似乎是一个代错误。但在编辑之后,我认为它现在可以正常工作了,我编译的时候没有错误,intellisense工作起来很有魅力。你所展示的一切在语法上都是有效的。除了名称空间中的不同大小写,但是前面已经提到了+我不确定名称空间是否区分大小写。但是,您正确地使用了静态类:)谢谢。我没有注意到这一点,尽管这很烦人,因为我自己没有添加名称空间(生成的),我不知道发生了什么。不管怎样,谢谢。