int[] array = new[] { 1, 2, 3, 4, 5 };
int first = array[0];
int second = array[1];
foreach(int i in array)
{
if (i > first)
{
second = i;
break;
}
}
for(int q = 0; q<array.Length; q++)
{
Console.WriteLine(array[q]);
}
Console.ReadKey();
int[] array = new[] { 1, 2, 3, 4, 5 };
int temp;
for (int i = 0; i < array.Length-1; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if (array[i] > array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
int[] array = new[] { 1, 2, 3, 4, 5 };
var tmp = array[0];
array[0] = array[1];
array[1] = tmp;
int[] array = new[] { 1, 2, 3, 4, 5 };
var maxindex = 0;
var max = array[maxindex];
for(var i = maxindex; i<array.Length; i++)
if (array[i] > max)
{
maxindex = i;
max = array[i];
}
var array = new[] { 1, 2, 3, 4, 5 };
(array[0], array[1]) = (array[1], array[0]);
.. и поискvar array = new[] { 1, 2, 3, 4, 5 };
var (maxindex, max) = (0, array[0]);
for(var i = maxindex; i<array.Length; i++)
if (array[i] > max)
(maxindex, max) = (i, array[i]);