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 關注
- 410 瀏覽
添加回答
舉報
0/150
提交
取消