我有用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