如何在c#中删除一个数组? [英] How to delete an array in c#?

查看:181
本文介绍了如何在c#中删除一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个明显的问题,我很抱歉,但无论是 Google 还是此处的搜索都没有让我找到答案.

I'm sorry if this is an obvious question but neither Google or a search here led me to an answer.

有没有办法完全删除数组?

Is there a way to remove an array entirely?

我想要int[] array = new int[5]

推荐答案

说你打电话:

 void Foo(){
     int[] a = new int[5];
 }

在 C# 中,无法取消定义变量 a.这意味着即使您将 a 设置为 null,a 也会在 Foo 中定义.但是,在 Foo 的末尾 a 将超出范围.这意味着没有代码可以引用它,垃圾收集器将在下次运行时为您释放内存,这可能不会持续很长时间.

In C# there is no way to undefine the variable a. That means a will be defined in Foo even if you set a to null. However, at the end of Foo a will fall out of scope. That means no code can reference it, and the garbage collector will take care of freeing the memory for you the next time it runs, which might not be for a long time.

这篇关于如何在c#中删除一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆