这个dotnet代码涉及哪些知识

来源:百度知道 编辑:UC知道 时间:2024/09/22 20:35:44
这是VS自动生成的,但这些
Dispose(bool disposing)
(components != null))
components.Dispose()

base.Dispose(disposing);
this.components = new System.ComponentModel.Container();System.ComponentModel.ComponentResourceManager(typeof(main));
涉及到哪些知识啊?我完全看不懂
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();

这段是资源释放代码. 不知道你具体哪里看不懂.

涉及到接口和继承知识.

接口:
实现了IDisposable

继承:
base.Dispose(disposing); 这句是释放基类中的资源
protected override void Dispose(bool disposing) 这句是改写了基类中Dispose方法.

//释放正在使用的资源
Dispose(bool disposing)
(components != null))
components.Dispose()
//调用基类中的资源释放方法
base.Dispose(disposing);
this.components = new System.ComponentModel.Container();System.ComponentModel.ComponentResourceManager(typeof(main));
//重写基类中的释放被占用资源的方法
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

总之。这一块儿是用来进行被占用资源释放的,这块儿的代码是自去生成的,不需要你去管,这是C#的一大特性,即“资源回收机制”

垃圾回收机制

厉害,关注