Answer the question
In order to leave comments, you need to log in
How to completely clear an array?
Good evening friends.
There is an array
public int[] checkAddDel;
checkAddDel = new int[Word.Length]
Answer the question
In order to leave comments, you need to log in
checkAddDel = new int[0]
An array always has a predefined length, which does not change, you can only create a new one with the desired size.
After use, you can do:
or
And the previously filled array will be destroyed by the garbage collector.
use static Array class with Resize method from msdn itself
var myArray = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Array.Resize(ref myArray, 0);
It might be better to take a list instead of an array:List<int>
public List<int> checkAddDel;
checkAddDel = new List<int>(Word.Length); // предварительно указывать размер не обязательно,
// но если известно заранее, то лучше указать
Console.WriteLine(checkAddDel.Count); // 0
for (var i = 0; i < Word.Length; i++)
{
checkAddDel.Add((i + 1) * 10);
}
Console.WriteLine(checkAddDel.Count); // размер теперь стал равным Word.Length
// используем список
DoWork(checkAddDel);
checkAddDel.Clear(); // теперь стал пустым
Console.WriteLine(checkAddDel.Count); // 0
The List list is no longer an option, a lot of rewriting)Actually, it's the only reasonable option. and if you master the features of VS refactoring, then it’s unlikely that you will rewrite too much
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question