こんにちは、私はオブジェクトのリストを持っています。私が持っている ID が既にリストにあるかどうかを調べる必要があります。オブジェクト クラスで ID を設定しました。Ui に入力された ID が既に使用されているかどうかを確認したいだけです。
クラス
class Product
{
private string name = "";
private int id = 0;
private decimal Pvalue = 0.00m;
private static int lastId = 1;
public Product(string namep, decimal valuep)
{
this.name = namep;
this.id = lastId++;
this.Pvalue = valuep;
}
public override string ToString()
{
return name + " " + id + " "+ Pvalue;
}
public bool Equals(Product p)
{
return (p.id == this.id);
}
}
私はそれを解決しようとしています:
int id;
bool test = int.TryParse(textBoxId.Text, out id);
if(test)
{
if(Inv.Contains(id))
{
label2.Text = "you already have this id";
}else
{
label2.Text = "you can use this id";
}
}
なぜこれが機能しないのか、またはより良い方法について誰かが考えを持っているなら、それは私の裏側を救うでしょうありがとう.