---
title: "Check if a variable is in an ad-hoc list of values"  
description: "Check if a variable is in an ad-hoc list of values"  
author: "Anonymous User"  
published: 2013-06-06  
updated: 2013-06-06  
canonical: https://www.mindstick.com/forum/1006/check-if-a-variable-is-in-an-ad-hoc-list-of-values  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Check if a variable is in an ad-hoc list of values

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances),\
Is there a shorter way of [writing](https://www.mindstick.com/articles/12997/5-essential-tips-on-resume-writing-for-business-analysts) something like this:\
**if(x==1 || x==2 || x==3)** // do something\
What I'm looking for is something like this:\
**if(x.in((1,2,3))** // do something\
Please help.Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

Hi Expert,\
You could achieve this by using the List.Contains method:\
**if(new []{1, 2, 3}.Contains(x))****{** **//x is either 1 or 2 or 3****}****\**I hope it helpful for you.


---

Original Source: https://www.mindstick.com/forum/1006/check-if-a-variable-is-in-an-ad-hoc-list-of-values

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
