考虑以下代码:
public class Class1
{
public static int c;
~Class1()
{
c++;
}
}
public class Class2
{
public static void Main()
{
{
var c1=new Class1();
//c1=null; // If this line is not commented out, at the Console.WriteLine call, it prints 1.
}
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine(Class1.c); // prints 0
Console.Read();
}
}
Run Code Online (Sandbox Code Playgroud)
现在,即使main方法中的变量c1超出范围并且在GC.Collect()调用时没有被任何其他对象进一步引用,为什么它没有在那里完成?
嘿家伙我有一个小问题,我似乎无法弄明白.我将DataGridView(它的内容)保存到xls文件.我没有遇到任何问题,除了我的任务管理器,它仍然显示它正在运行.我打过电话:
xlApp.Application.Quit()
Run Code Online (Sandbox Code Playgroud)
这被声明为:
Dim xlApp As New excel.Application
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用,但这与我让用户选择将其导出到Word文档时退出的方式相同.我不知道我哪里错了...
这是我的完整代码
Imports Word = Microsoft.Office.Interop.Word
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For x As Integer = 1 To 3500
DataGridView1.Rows.Add(New Object() {"r" & x.ToString & "c1", "r" & x.ToString & "c2", "r" & x.ToString & "c3", "r" & x.ToString & "c4", "r" & x.ToString & "c5"})
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As …Run Code Online (Sandbox Code Playgroud)