準備
(なし)
デザイン
- フォーム (Form1) にボタン (button1) を配置します。
- フォーム (Form1) にリストボックス (listBox1) を配置します。
サンプルコード (C#)
namespace WinFormsApp1
{
public partial class Form1 : Form
{
private int i;
private bool b;
private char c;
private object obj;
private string s;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.AllowDrop = true;
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(i);
listBox1.Items.Add(b);
listBox1.Items.Add(c);
//listBox1.Items.Add(obj);
//listBox1.Items.Add(s);
}
}
}
解説
メンバー変数は自動的に初期化されます。
・数値型: 0
・論理型: false
・キャラクタ型: \0 (null)
・オブジェクト型: null
・文字列型: null
結果
動作確認環境
Visual Studio 2022 Professional (.NET 7 C#11)
ログ
初版:2016.06.08 Visual Studio 2015 Professional (C# 6.0)
