How to Compare List<> values with a Textbox

i am fetching product id from invoice table in a list CheckProduct(int id):

int id = int.Parse(invoice_no.Text);  // passing textbox value to list
SPBusinesslogic ab = new SPBusinesslogic();
List<SPBusinesslogic> invv = new List<SPBusinesslogic>();
invv = ab.CheckProduct(id);

 if (invv.Equals(int.Parse(up_invno_txtbox.Text)))  /comparing values in list
    {
        MessageBox.Show("the product already exist");
    }
    else
    {  //add new product code
    }

i am unable to compare the value by this let me know if i am committing any mistake.

CheckProduct:

public List<SPBusinesslogic> CheckProduct(int id)
{
    try
    {
        SPDatalogic sp = new SPDatalogic();
        DataTable dt = new DataTable();
        dt = sp.CheckProduct(id);
        List<SPBusinesslogic> invinfo = new List<SPBusinesslogic>();
        foreach (DataRow dr in dt.Rows)
        {
            SPBusinesslogic ab = new SPBusinesslogic();
            ab.Pro_id = int.Parse(dr[0].ToString());

            invinfo.Add(ab);
        }
        return invinfo;
    }
    catch (Exception e)
    {
        throw new Exception(e.Message);
    }
Jon Skeet
people
quotationmark

I suspect you want something like:

// TODO: Give your variables more meaningful names throughout...
int id = int.Parse(up_invno_txtbox.Text);
if (invv.Any(item => item.Id == id))
{
    ...
}
else
{
    ...
}

Obviously adjust the use of item as per your requirements, but this general pattern is suitable for finding an existing match for a predicate.

people

See more on this question at Stackoverflow