winform的后置代码,没有对变量message进行初始化赋值,怎么可以进行赋值运算了

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 对话框
{
public partial class Form2 : Form
{
 public string message; 

public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
  label.Text = message; 




private void button1_Click(object sender, EventArgs e)
{

this.Close();
}


}
}

生成一个这样的窗体

(逐语句过程调试)监视窗口显示messagenullstring,这不是会引发编译错误吗,难道在 label.Text = message中的message跟public string message中的message变量时不同的,求解救


慕桂英546537
浏览 396回答 2
2回答

开满天机

message没有赋值会默认string.empty, label.Text 支持赋string.empty.string str="",表示一个空串,被实列化了,占用了内存空间,   string str=null,表示一个空引用,并没有指向任何地方,没有占用了空间,   string str 或string.empty.因为C#里边你不初始化的话会有一个默认值。
打开App,查看更多内容
随时随地看视频慕课网APP