Before, had been talking. NET Framework aspects of the problem, today to talk about the use of array and list, this should be considered the most basic of the algorithm of things. Just to remind you to pay attention to this problem.
Write this because of a classmate's help, the thing is like this, he is responsible for the company's a training module, in the training module, there is a function of automatic volume. Then, it's easy to think of the shuffle algorithm. So I explained to him the process and steps of the shuffle algorithm, and he gave me the code and proudly told me that he used generics ...
List<int> list = new List<int>();
for (int i = 0; i < 10; i++)
{
list.Add(i);
}
Random r = new Random();
for (int j = 0; j < 100; j++)
{
int temp;
int x1 = r.Next(10);
int x2 = r.Next(10);
temp = list[x1];
list[x1] = list[x2];
list[x2] = temp;
}
I gently told him that he had a bad method and wrote down the following code:
int[] array = new int[10];
for (int i = 0; i < 10; i++)
{
array[i] = i;
}
Random r = new Random();
for (int j = 0; j < 100; j++)
{
int temp;
int x1 = r.Next(10);
int x2 = r.Next(10);
temp = array[x1];
array[x1] = array[x2];
array[x2] = temp;
}
He said to me very disdain, not all the same! And still in the use of generics for the proud! I have no words ...
I just replaced the list with an array, and some people would say, is that a big relationship?