Question: How do I check if user input matches a number in an array? 

I've learned to compare user input or search using a string array, however doing the same with an int array is not working for me. 

```
zipCode[i] = 0;
int userZip = 0;

do 
{
    Console.WriteLine( "enter a 5 digit zip code to see if it is supported in our area." );
    Console.WriteLine( );
    Console.WriteLine( "Enter a 0 to exit the program" );
    userZip = 0;
    if ( userZip == zipCode[i] ) 
    {
        found = true;
        if ( found ) 
        {
            Console.WriteLine( "We support zip code {0}", userZip ); ;
        } 
        else 
        {
            Console.WriteLine( "We do not support", userZip );
        }
    }
} while ( userZip != 0 );

Console.ReadLine( );

```

Answer: 
> 
> How do I check if user input matches a number in an array?
> 
> 
> 

```
using System;
using System.Collections.Generic;

public class Program
{
    static List<string> _zipCodes;

    static Program()
    {
        _zipCodes = new List<string>() { "80205", "80225", "80210" };
    }

    static void Main(string[] args)
    {
        string userZip = string.Empty;

        do
        {
            Console.WriteLine("enter a 5 digit zip code to see if it is supported in our area.");
            Console.WriteLine();
            Console.WriteLine("Enter a -1 to exit the program");
            userZip = Console.ReadLine();

            if (_zipCodes.Contains(userZip))//<---------------THAT WAY
            {
                 Console.WriteLine("We support zip code {0}", userZip); ;
            }
            else
            {
                Console.WriteLine("We do not support zip code {0}", userZip);
            }

        } while (userZip != "-1");

    }
}

```
TheFastCat beat me, but:

```
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        private static IEnumerable<string> zipCodes = new string[] { "90210", "94102", "98101", "80014" };

        static void Main(string[] args)
        {

            Console.WriteLine("enter a 5 digit zip code to see if it is supported in our area, or '0' to exit");
            do {
                // Read next line
                string userZip = Console.ReadLine().Trim();

                // Exit program?
                if (userZip == "0")
                    break;

                // Validate input
                if (userZip.Length != 5)
                {
                    Console.WriteLine("ERROR: Zip code {0} is {1} characters; expected 5", userZip, userZip.Length);
                    continue;
                }
                int n;
                bool isNumeric = int.TryParse(userZip, out n);
                if (!isNumeric)
                {
                    Console.WriteLine("ERROR: Zip code {0} must be numeric", userZip);
                    continue;
                }

                // Finally, see if our zip code matches a zip code in the list
                bool found = zipCodes.Contains(userZip);
                if (found)
                {
                    Console.WriteLine("We support zip code {0}", userZip); ;
                }
                else
                {
                    Console.WriteLine("We do not support " + userZip);
                }
            } while (true);
            Console.WriteLine("Done: exiting program");
        } 
    }
}

```

Note:

1. Initializing the list
2. Validating the input
3. Using [IEnumerable.Contains()](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1?view=netframework-4.7.2) ... *without* necessarily messing with LINQ.
4. Use of "break" and "continue" to control the loop, *without* necessarily needing an extraneous variable.