Use Enumerable.Contains<T>
which is an extension method on IEnumerable<T>
:
var strings = new List<string> { "A", "B", "C" };
string x = // some string
bool contains = strings.Contains(x, StringComparer.OrdinalIgnoreCase);
if(contains) {
// do something
}
More Related Contents:
- Why .NET String is immutable? [duplicate]
- Escape double quotes in a string
- Why would you use String.Equals over ==? [duplicate]
- Efficient way to remove ALL whitespace from String?
- Comparing two strings, ignoring case in C# [duplicate]
- What’s does the dollar sign ($”string”) do? [duplicate]
- How to format a string as a telephone number in C#
- How the StringBuilder class is implemented? Does it internally create new string objects each time we append?
- Test if string is a guid without throwing exceptions?
- How is GetHashCode() of C# string implemented?
- How to include quotes in a string
- How do I interpolate strings?
- C# testing to see if a string is an integer?
- String sorting issue in C#
- How to know the size of the string in bytes?
- Convert array of integers to comma-separated string
- Easiest way to parse a comma delimited string to some kind of object I can loop through to access the individual values?
- Convert string to decimal, keeping fractions
- How to do ToString for a possibly null object?
- String.Format – how it works and how to implement custom formatstrings
- Check if a string is a palindrome
- .NET method to convert a string to sentence case
- Why does .ToString() on a null string cause a null error, when .ToString() works fine on a nullable int with null value?
- How to check if a String contains any letter from a to z? [duplicate]
- Fastest way to check if string contains only digits in C#
- Does C# have a String Tokenizer like Java’s?
- Convert String^ in c# to CString in c++/CLI
- How can I check if a string contains a character in C#?
- Parsing formatted string
- Parsing through Arabic / RTL text from left to right