C# Tcpclient构造函数问题#
我正在尝试创建一个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 //
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: