2013-09-30 52 views
1

我想創建一個TcpClient的,並與構造有問題......TcpClient的構造問題C#

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); 

我得到錯誤:

Error 1 'TcpClient' does not contain a constructor that takes 2 arguments

我的問題:

爲什麼會出現這個問題&如何解決它?

+0

你爲什麼要創建一個TcpClient的時候就已經有內置的框架這樣的班:http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx –

回答

3

這是因爲您的類被命名爲TcpClient,它與框架中類的名稱相同,如解釋here所述。只要給你的班級一個不同的名字。

可以很明顯的也用命名空間來指示編譯器到底是哪的TcpClient類,你指的是,例如

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

非常感謝您的幫助! – RamHS