Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Tcpclient构造函数问题#_C#_Constructor_Client_Tcpclient - Fatal编程技术网

C# Tcpclient构造函数问题#

C# Tcpclient构造函数问题#,c#,constructor,client,tcpclient,C#,Constructor,Client,Tcpclient,我正在尝试创建一个TcpClient,但构造函数有问题 public class TcpClient : IDisposable { static void Connect(String server, String message) { try { // Create a TcpClient. // Note, for this client to work you need to have a TcpServer //

我正在尝试创建一个TcpClient,但构造函数有问题

public class TcpClient : IDisposable
{
static void Connect(String server, String message)

{
    try
    {
        // Create a TcpClient. 
        // Note, for this client to work you need to have a TcpServer  
        // connected to the same address as specified by the server, port 
        // combination.
        Int32 port = 9000;
        TcpClient client = new TcpClient(server, port);
我得到一个错误:

错误1“TcpClient”不包含接受2的构造函数 论据

我的问题:


为什么会出现此问题以及如何解决此问题?

这是因为您的类名为TcpClient,与框架中的类同名,如前所述。给你的班级起一个不同的名字

例如,您显然还可以使用名称空间向编译器精确指示您所引用的TcpClient类

new System.Net.Sockets.TcpClient.TcpClient(server, socket);

既然框架中已经内置了这样的类,为什么还要尝试创建TcpClient: