Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:00:59+00:00 2026-06-01T16:00:59+00:00

This is not a specific question but a generic question which was in my

  • 0

This is not a specific question but a generic question which was in my mind from long time

I have to check one variable if it contains a value from a list of strings

for e.g.

status == "Open" || status =="Active" || status =="Reopen" || status = "InActive" etc..

In SQL it is very easy to write this kind of statements e.g.

select * from ticket where status in (“Open”,”Active”,”Reopen”,”InActive)

I wonder we don’t have such easy statement in C#?

Do anybody know any easy way like SQL to write this kind of statements without using generic types of if else ,foreach loop or LINQ etc..

I know LINQ is there but still it is not as simple as IN of sql

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:01:01+00:00Added an answer on June 1, 2026 at 4:01 pm
    tickets.Where(t => new[] {"Open",
                              "Active",
                              "Reopen",
                              "InActive"}.Any(x => x == t.status))
    

    You can also use the Contain method instead of the Any method, but use the Any method if there’s any comparement logic you would like to implement, instead of the default equality comparer.

    OR

    Implement extensions to support IN method:

    public static class Extensions
    {
        public static bool In<TItem>(this TItem source, Func<TItem, TItem, bool> comparer, IEnumerable<TItem> items)
        {
            return items.Any(item => comparer(source, item));
        }
    
        public static bool In<TItem, T>(this TItem source, Func<TItem, T> selector, IEnumerable<TItem> items)
        {
            return items.Select(selector).Contains(selector(source));
        }
    
        public static bool In<T>(this T source, IEnumerable<T> items)
        {
            return items.Contains(source);
        }
    
        public static bool In<TItem>(this TItem source, Func<TItem, TItem, bool> comparer, params TItem[] items)
        {
            return source.In(comparer, (IEnumerable<TItem>)items);
        }
    
        public static bool In<TItem, T>(this TItem source, Func<TItem, T> selector, params TItem[] items)
        {
            return source.In(selector, (IEnumerable<TItem>)items);
        }
    
        public static bool In<T>(this T source, params T[] items)
        {
            return source.In((IEnumerable<T>)items);
        }
    }
    

    And use like this:

    bool b;
    
    b = 7.In(3, 5, 6, 7, 8); // true
    b = "hi".In("", "10", "hi", "Hello"); // true
    b = "hi".In("", "10", "Hi", "Hello"); // false
    b = "hi".In((s1, s2) => string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase), "", "10", "Hi"); // true
    
    var tuples = new List<Tuple<int, string>>();
    
    for (var i = 0; i < 10; i++)
    {
        tuples.Add(Tuple.Create(i, ""));
    }
    
    var tuple = Tuple.Create(3, "");
    
    b = tuple.In(tup => tup.Item1, tuples); // true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen a few posts regarding this issue but not one specific to
I know this specific question has been asked before , but I am not
the title might be too generic, but I have a very specific question about
This is a pretty generic question, but I come from a few years with
First of I'm very sorry but this questions is not so so specific. All
Note This is not a REBOL-specific question. You can answer it in any language.
This is a question not really about programming (is not specific to any language
This is not a question about a specific framework. I am using plain php
This is a general question. And may not be specific to datagrids. How can
(This question does not rely on a specific IoC framework, so the interfaces and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.