[C#] ตัวแปร Struct

โค้ด
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public struct MyStruct
        {
            public string name;
            public int age;
            public bool married;
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            MyStruct myRecord;
            myRecord.name = textBox1.Text;
            myRecord.age = int.Parse(textBox2.Text);
            myRecord.married = checkBox1.Checked;

            string strOut = "";
            strOut += "myRecord.name : " + myRecord.name + "\n";
            strOut += "myRecord.age : " + myRecord.age.ToString() + "\n";
            strOut += "myRecord.married : " + myRecord.married.ToString() + "\n";

            MessageBox.Show(strOut);
        }
    }
}
Previous
Next Post »