準備
(なし)
デザイン
1. フォーム (Form1) にボタン (button1) を配置します。
2. フォーム (Form1) にリストボックス (listBox1) を配置します。
サンプルコード (C#)
// 名前空間の追加
// (なし)
// 構造体の宣言
struct stComputer
{
public string sMaker;
public string sPCName;
}
// コード
private void button1_Click(object sender, EventArgs e)
{
stComputer st1 = new stComputer { sMaker = "NEC", sPCName = "ValueStar" };
stComputer st2 = new stComputer { sMaker = "SONY", sPCName = "VAIO" };
stComputer st3 = new stComputer { sMaker = "DELL", sPCName = "Precision" };
List<stComputer> lt = new List<stComputer>();
lt.Add(st1);
lt.Add(st2);
lt.Add(st3);
foreach (stComputer item in lt)
{
listBox1.Items.Add(item.sMaker + " " + item.sPCName);
}
}
解説
ジェネリックコレクションの型に構造体を指定しています。
結果

動作確認環境
Visual Studio 2015 Professional (C# 6.0)