我有用c#編程的WPF客戶端。該程序是一個註冊演示,您鍵入一個名稱並說出他們是否在這裏,然後將其發送到用戶輸入到文本框中的服務器和端口。錯誤:「非靜態字段,方法或屬性需要對象引用...」
但試圖在代碼中應用此代碼時,出現錯誤:「非靜態字段,方法或屬性需要對象引用...」。 這是對「client.connect」行......
namespace client
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public class connectandsend
{
//if 'REGISTER' button clicked do this...{
static void connect()
{
TcpClient client = new TcpClient(); // New instance of TcpClient class of the .Net.Sockets
client.Connect(server_txt.Text, Convert.ToInt32(port_txt.Text)); // Server, Port
StreamWriter sw = new StreamWriter(client.GetStream()); // New StreamWriter instance
StreamReader sr = new StreamReader(client.GetStream()); // New StreamReader instance
}
/* static void send()
{
stream write... name.text and 'here' or 'not here' ticked box?
}
}
*/
}
}
}
請把t他超時閱讀以下內容 [如何提出問題](http://stackoverflow.com/help/how-to-ask) – MethodMan
做出了改變,希望它足夠好,謝謝。 – HJagger95