public struct Student
{
    public string ID;
    public string Name;
    public int? Score;  // 只要在型別後面加上一個問號「?」就變成可存放null的資料型別
}
private void Form1_Load(object sender, EventArgs e)
{
    Student[] Std = new Student[2];
    Std[0].ID = "G095001";
    Std[0].Name = "許清榮";
    Std[0].Score = null;

    Std[1].ID = "G095002";
    Std[1].Name = "買大誠";
    Std[1].Score = 100;

    foreach (Student var in Std)
    {
        if (var.Score == null)
        {
            MessageBox.Show(this, var.Name + "成績不存在");
        }
    }
}

arrow
arrow
    全站熱搜

    羅 朝淇 發表在 痞客邦 留言(0) 人氣()