int answerrandom = Random.range (0,4); The tip says it includes the minimum value, not the maximum, which includes 0 excluding 4, and the experimental results are no more than 4 out of 3. int answerRandom1 = Random.range (daan1[0],daan1[3]); A random range can directly use an array of if (TX3). ToString () ==bttona.text) This is converted to the same type using
Long time no research programming. Array.Sort (numbers); Is a quick sort method, by default, from small to large sort
Using System.Collections.Generic; Add this space to use the array List
static void Main (string[] args)
{
int[] numbers = new INT[10];
Random rnd = new Random ();
for (int i = 0; i < i++)
{
Numbers[i] = rnd. Next (100);//We use random numbers to increase the fun of practice
}
Console.WriteLine ("Initialization:");
Display (numbers);
Console.WriteLine ("After sort:");
Array.Sort (numbers);
Display (numbers);
Console.read ();
}
static void Display (int[] numbers)
{
foreach (var item in numbers)
{
Console.Write (item + ",");
}
Console.WriteLine ();
}
The result is an initialization of 17 19 96 98 15 16 25
After sorting, the result is 15 16 17 19 25 96 98
You see, it's easy to sort it out. The default is ascending. So how do you keep him in descending order?
Class intcomparer:icomparer<int>
{
#region Icomparer<int> Members
public int Compare (int x, int y)
{
if (_type = = "DESC")
return Y.compareto (x);//We're just going to turn it around, and we're in a descending order.
Else
return X.compareto (y);
}
#endregion
private string _type = "ASC";
Public Intcomparer (String type)
{
_type = type;
}
}
Then, in the calling code
Console.WriteLine ("Initialization:");
Display (numbers);
Console.WriteLine ("After sort:");
Array.Sort (Numbers, new Intcomparer ("DESC"));