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

  • Home
  • SEARCH
  • 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 7728111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:38:08+00:00 2026-06-01T05:38:08+00:00

I am trying to write a conditional to determine if an unknown integer ‘a’

  • 0

I am trying to write a conditional to determine if an unknown integer ‘a’ is equivalent to a set of known constants, x, y or z. In some languages, like delphi this can be done as follows:

if (a in [x, y, z]) then
begin
   //do something
end;

I am working in C#, however, so this does not work. There are obvious ways to do it but I have been unable to find an equivalently simple way to do it and was wondering if one exists.

Thanks for ahead of time for any suggestions.

  • 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-01T05:38:09+00:00Added an answer on June 1, 2026 at 5:38 am

    You could use:

    if (new[] { x, y, x }.Contains(a))
    

    (Note that this requires either LINQ to Objects and a using directive of using System.Linq; or an ugly cast to ICollection<int>.)

    Or better, just create the set once, e.g.

    private static readonly HashSet<int> ValidValues = new HashSet<int> { 1, 2, 3 };
    
    ...
    
    if (ValidValues.Contains(a))
    

    If the number of elements is fairly small, then actually an array may well be faster than a HashSet:

    private static readonly int[] ValidValues = { 1, 2, 3 };
    

    Or wrap it in a read-only collection if you don’t trust yourself not to modify it in your class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some microcontroller code using Texas Instruments examples, and it uses
I am trying to write a conditional if statement helper for Handlebars.js. Essentially, I
I'm not a php expert so I'm having some trouble trying to write a
I'm trying to write a conditional for when an object property's value is blank,
I am trying to write a simple internal app with some simple authentication. I'm
I'm trying to write a SQL Statement that should function like the below Linq
I am trying to write some code to calculate dividend yields. I need to
I'm trying write a query to find records which don't have a matching record
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
Trying to write a couple of functions that will encrypt or decrypt a file

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.