Largest and smallest number in an array
<p>This works perfectly...but when I use <code>foreach</code> instead of <code>for</code> this doesn't works. I can't understand <code>for</code> and <code>foreach</code> are same.</p>

<pre><code>namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = new int[10];
            Console.WriteLine("enter the array elements to b sorted");
            for(int i=0;i&lt;10;i++)
            {
                array[i] = Convert.ToInt32(Console.ReadLine());
            }
            int smallest = array[0];
            for(int i=0;i&lt;10;i++)

            {
                if(array[i]&lt;smallest)
                {
                    smallest=array[i];

                }
            }
            int largest = array[9];
            for(int i=0;i&lt;10;i++)
            {

                if (array[i] &gt; largest)
                {
                    largest = array[i];

                }
            }
            Console.WriteLine("the smallest no is {0}", smallest);
            Console.WriteLine("the largest no is {0}", largest);
            Console.Read();


        }
    }
}
</code></pre>
