vb.net:清除字符串数组的所有内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1638998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vb.net: clearing all contents of string array
提问by l--''''''---------''''''''''''
i have this:
我有这个:
Dim split As String() = temp_string.Split(",")
''#feed all info into global variables
patient_id = split(0)
doc_name = split(1)
lot__no = split(2)
patient_name = split(3)
how do i clear all the contents of split() ?
我如何清除 split() 的所有内容?
回答by ChaosPandion
Array.Clear(split, 0, split.Length)
回答by xpda
ReDim split(-1)
回答by Sean
No need to do anything. The garbage collector will do its jobs clearing the variable. Explicitly set every variable to nothing will slow down your application.
不需要做任何事情。垃圾收集器将完成清除变量的工作。将每个变量显式设置为空会减慢您的应用程序的速度。
回答by Fredrik M?rk
You can always set it to Nothing
which will clear the reference. Then the garbage collector will take care of the rest when it finds that to be a good idea.
您始终可以将其设置为Nothing
清除引用。然后垃圾收集器会在它发现这是一个好主意时处理剩下的事情。
split = Nothing
However, if this is a local variable of a method you would typically not need to worry about this, the array will be available for garbage collection as soon as it goes out of scope.
但是,如果这是一个方法的局部变量,您通常不需要担心这一点,一旦超出范围,该数组将可用于垃圾收集。