Binary Search Optimization Can anyone give me recommendations on how to improve my code?

using System;
namespace mybinsearch2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int key = int.Parse(Console.ReadLine());
            int[] arr = new int[n];  int min = 0;int max = n - 1;
            int mid = min + (max - min) / 2;int temp;
            for (int i = 0; i &lt;= n - 1; i++)
            {
                arr[i] = i *5;
            }
            while (true)
            {
                temp = arr[mid];
                if (arr[mid] == key)
                {
                    Console.WriteLine("Position is: " + mid); break;
                }
                else if (arr[mid] &lt; key) min = mid;
                else max = mid;
                mid = min + (max - min) / 2;
                if(arr[mid]==temp)
                {
                    Console.WriteLine("Not Found"); break;
                }
            }

       }
    }
}
If you have repeating values I think the second if(arr[mid]==temp) can fail.  

Separate the create the test from the program (method).  Return a value from method and print it in the test.

The first if (arr[mid] == key) that is the least likely condition so put it last and  it can just be an else as you should test for &lt; and > so = is all that is left.  

You repeatedly reference arr[mid] when you already have it temp = arr[mid];

You have max = n - 1; but you don't use it in the create test loop    

Put assignments on separate lines
This still has problems - this is just cleaning up existing code 

static void Main(string[] args)
{
    int n = int.Parse(Console.ReadLine());
    int key = int.Parse(Console.ReadLine());
    int[] arr = new int[n];
    int min = 0;
    int max = n - 1;
    int mid = min + (max - min) / 2;
    int temp;
    for (int i = 0; i &lt;= max; i++)
    {
        arr[i] = i * 5;  
    }
    while (true)
    {
        temp = arr[mid];
        if (temp &lt; key)
        {
            min = mid;  // this seems backwards but that is what you have
        }
        else if (temp &gt; key)
        {
            max = mid;
        }
        else
        {
            Console.WriteLine("Position is: " + mid);
            break;
        }
        mid = min + (max - min) / 2;
        if (arr[mid] == temp)  // this still has problems
        {
            Console.WriteLine("Not Found");
            break;
        }
    }
}