【发布时间】:2012-03-12 14:36:05
【问题描述】:
我搜索了一段时间并没有找到解决方案,还是我没有看到这个小错误?
我用 Visual C# 编写了一个程序,并且有 Form1.cs 程序.cs 服务器.cs
服务器.cs
namespace WindowsApplication1 {
class testServer {
public Form1 form1;
form1.send("data");
程序.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs
namespace WindowsApplication1
{
public partial class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private testServer Server;
private void startServer_Click(object sender, System.EventArgs e)
{
Server = new Server(data);
Server.form1 = this;
}
一切正常,但在 Server.cs 中,form1.send("data"); 出现空异常
看来form1真的是空的,但为什么呢?
我在哪里忘记了什么?
【问题讨论】:
-
form1.send("data");不在函数内部。