c# find if value exists in List c sharp

[sam_ad id=”48″ codes=”true”]Hi Guys,

Thought that I should share this with you.

Many times we will end up using List as our collection holder.

And that many time we wonder how to find if a value exists in List.

There are many ways you can do it. I’ll show you a couple which required less coding.

I must admit that I am not a c# pro but learning it on the go for my home made tools which requires me to get my hands dirty with c#.

Alright now lets get to the point

First we create a List.

Below is a basic List object

[geshi lang=”csharp” nums=”1″ target=”_self” ]

Now lets check if value “hello” exist in lt1or not


[geshi lang=”csharp” nums=”1″ target=”_self” ]

I am using LINQ expression above. Above line should leave value “True” in variable “exist

Another way is using function Find on List

[geshi lang=”csharp” nums=”1″ target=”_self” ]

Above line will leave txt with value hello

There are other handy methods to find value in List but I found above the most useful. One liners and does the Job nicely

I hope this helps


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.