简体   繁体   English

Tcpclient构造函数问题C#

[英]Tcpclient constructor Problems C#

I am trying to create a TcpClient and having problems with the constructor... 我试图创建一个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);

I get error: 我收到错误:

Error 1 'TcpClient' does not contain a constructor that takes 2 arguments 错误1'TcpClient'不包含带有2个参数的构造函数

My question: 我的问题:

why does this problem occurs & how to solve it? 为什么会出现这个问题以及如何解决?

This is because your class is named TcpClient which is the same name given to the class in the framework, as explained here . 这是因为你的类名为TcpClient的这是考虑到这个框架中的类相同的名称,如解释在这里 Just give your class a different name. 只要给你的班级一个不同的名字。

You can obviously also use the namespace to indicate to the compiler exactly which TcpClient class you are referring to, for example 显然,您也可以使用命名空间向编译器指明您所指的是哪个TcpClient类

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM