C# Multiple String Comparision with Same Value
c#, string
Solution
In C# 3.0, you can write a very trivial extension method:
public static class StringExtensions
{
public static bool In(this string @this, params string[] strings)
{
return strings.Contains(@this);
}
}
Then use it like this:
if ("some string".In(string1, string2, string3, string4))
{
// Do something
}
Problem
Please have a look at the below case, surely that will be interesting.. if i want to assign same value to multiple objects i will use something like this ``` string1 = string2 = string3 = string 4 = "some string"; ``` Now what i want to do is, i want to compare string1, string2, string3 and string4 with "someotherstring"... questions is is there any way to do this without writing individual comparision. i.e. ``` string1 == "someotherstring" || string2 == "someotherstring" || string3 == "someotherstring" || string4 == "someotherstring" ``` Hope i was able to explain the question.. kindly provide me help on this. Regards, Paresh Rathod