お世話になります。
class A
{
public string name;
public int age = 0;
public A(string _name)
{
this.name = _name;
}
}
上記の様な自作クラスをListBoxの要素として設定した後、
A.nameが"阿部"等といった要素を取り出し、そのインデクスを
選択状態にするソースを組んでいます。
現段階では、forで一つ一つ回しながらAクラスを拾い、
一つ一つA.nameと比較していくソースになっていますが、
もっと良い方法はありますでしょうか。
http://dobon.net/vb/dotnet/programing/arrayfilter.html
こちらのサイト様のように、Arrayクラスを使った方法ができるような
きがするのですが、よく解りませんでした。
未熟な質問で恐れ入りますが、何卒よろしくお願いいたします。
現在のソースは下記のようになっています。
===========================================================
// string[] stArray 表示させるための前段階の文字列配列
this.lstbox1.Items.Clear();
foreach (string s in stArray)
{
this.lstbox1.Items.Add(new A(s));
}
public string _Value
{
get
{
A a = (A)this.lstbox1.SelectedValue;
return a.name;
}
set
{
// ↓この部分をfor,foreachを使わずに行いたい
foreach(A d in this.lstbox1.Items)
{
if (d.name == value)
{
this.lstbox1.SelectedValue = d;
break;
}
}
}
}