Problem with Visual C # [closed]

0

I am learning the language and I am doing a calculator to start with. The calculator should have a small system that simulates a memory where the numbers are stored. For example, if I write 56 and give it to the sum button, the number 56 should be saved in an array and if I write 10 later or leave 56 again, that number should be nested in the array as well. The numbers are saved very well, but when I use Array.Clear (numbers, 0, numbers.Length) it does not seem to do anything and the program continues normally. Why is it not so easy to empty an array with C #? With Visual Basic.NET, that was easy. Here it is completely different.

    
asked by Máxima Alekz 02.07.2016 в 08:27
source

1 answer

3

If you want to empty an array, you can do it like that

 int[] x = new int[10];
Array.Clear(x, 0, x.Length);

//  Sets a range of elements in an array to the default value of each element type.

But keep in mind that it is an array, it is not empty ... it is equal to the default value of the array (in this case it is 0), since the array has a fixed dimension.

If you want to empty, and modify this dimension I advise you to use a list

List<int> lista=new List<int>();

and to empty it

lista.Clear();
    
answered by 02.07.2016 в 11:53