元ネタ
[.NET] DataGridViewのDataSourceにnullを持つObjectArrayを入れたらどう表示されるか - Qiita
だいたい予想通りで、
int型 : 0
string型 : 空白
bool型 : false
birthday : 空白
で表示される。
Nullable型
int型 : 0
とbool型 : false
は厳密にはnullではなくただの初期値なのでNullable型にした場合の動きはどうなるのだろう。
class Person
{
public int? id { get; set; }
public string name { get; set; }
public bool? sex { get; set; }
public DateTime birthday { get; set; }
}
private void Form1_Load(object sender, EventArgs e)
{
var persons = new List<Person>();
persons.Add(new Person() { id = 1, name = "鹿目まどか", birthday = new DateTime(2010, 10, 3), sex = false });
persons.Add(new Person() { id = 2, name = "暁美ほむら", sex = false });
persons.Add(new Person() { id = 3, name = null, sex = false });
persons.Add(new Person() { id = 4, name = "巴マミ" });
persons.Add(new Person() { id = 5, name = "佐倉杏子", sex = false });
persons.Add(new Person() { name = "キュゥべえ", sex = true });
dataGridView1.DataSource = persons.ToArray();
}