---
title: "Compare input to list"  
description: "Compare input to list"  
author: "Manoj Bhatt"  
published: 2013-12-17  
updated: 2013-12-17  
canonical: https://www.mindstick.com/forum/1790/compare-input-to-list  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Compare input to list

Is it possible to [compare](https://www.mindstick.com/forum/2036/propertyinfo-getvalue-unable-to-compare-datetimes) the [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) in a [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) in a [windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) to the [items](https://www.mindstick.com/forum/33812/getting-number-of-items-selected-in-uicollectionview-in-ios) in a list and then save it if it doesn't exist there.

```
public Form1(){    InitializeComponent();    if (txtId.Text == Id.myList)    {        myList.Add(txtId.Text);    }    else (){        MessageBox.Show("Id already exists");    }}
```

## Replies

### Reply by Pravesh Singh

Hi Manoj,

You can loop trough all the items in the list and create a bool variable to check whether you have found the value in the list.

```
bool _Found = false;foreach (string a in list){    if (a == textBox1.Text)    {        _Found = true;        break;    }    else        _Found = false;}if (_Found) { }else { list.Add(textBox1.Text) }Or use List(T).Contains Methodif (list.Contains(textBox1.Text)) { }
```


---

Original Source: https://www.mindstick.com/forum/1790/compare-input-to-list

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
