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变量时不同的,求解救
2 回答

开满天机
TA贡献1786条经验 获得超13个赞
message没有赋值会默认string.empty, label.Text 支持赋string.empty.
string str="",表示一个空串,被实列化了,占用了内存空间,
string str=null,表示一个空引用,并没有指向任何地方,没有占用了空间,
string str 或string.empty.因为C#里边你不初始化的话会有一个默认值。
- 2 回答
- 0 关注
- 395 浏览
添加回答
举报
0/150
提交
取消