分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

// --------------------------------------------------------------------------------------------------------------------// <copyright file="DisposeExample.cs" company="Chimomo's Company">//   Respect the work.// </copyright>// <summary>//   Defines the DisposeExample type.// </summary>// --------------------------------------------------------------------------------------------------------------------// The following example demonstrates how to create a resource class that implements the IDisposable interface and the IDisposable.Dispose method.namespace CSharpLearning{    using System;    using System.ComponentModel;    /// <summary>    /// The dispose example.    /// </summary>    public static class DisposeExample    {        /// <summary>        /// The main.        /// </summary>        public static void Main()        {            // Insert code here to create and use the MyResource object.        }        /// <summary>        /// The my resource.        /// A base class that implements IDisposable. By implementing IDisposable, you are announcing that instances of this type allocate scarce resources.        /// </summary>        public class MyResource : IDisposable        {            /// <summary>            /// The handle.            /// Pointer to an external unmanaged resource.            /// </summary>            private IntPtr handle;            /// <summary>            /// The component.            /// Other managed resource this class uses.            /// </summary>            private readonly Component component = new Component();            /// <summary>            /// The disposed.            /// Track whether Dispose has been called.            /// </summary>            private bool disposed = false;            /// <summary>            /// Initializes a new instance of the <see cref="MyResource"/> class.            /// The class constructor.            /// </summary>            /// <param name="handle">            /// The handle.            /// </param>            public MyResource(IntPtr handle)            {                this.handle = handle;            }            /// <summary>            /// The dispose.            /// Implement IDisposable. Do not make this method virtual. A derived class should not be able to override this method.            /// </summary>            public void Dispose()            {                this.Dispose(true);                // This object will be cleaned up by the Dispose method. Therefore, you should call GC.SupressFinalize to take this object off the finalization queue and prevent finalization code for this object from executing a second time.                GC.SuppressFinalize(this);            }            /// <summary>            /// The dispose.            /// Dispose(bool disposing) executes in two distinct scenarios.            /// If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed.            /// If disposing equals false, the method has been called by the runtime from inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed.            /// </summary>            /// <param name="disposing">            /// The disposing.            /// </param>            protected virtual void Dispose(bool disposing)            {                // Check to see if Dispose has already been called.                if (!this.disposed)                {                    // If disposing equals true, dispose all managed and unmanaged resources.                    // Dispose managed resources.                    if (disposing)                    {                        this.component.Dispose();                    }                    // Call the appropriate methods to clean up unmanaged resources here.                    // If disposing is false, only the following code is executed.                    CloseHandle(this.handle);                    this.handle = IntPtr.Zero;                    // Note disposing has been done.                    this.disposed = true;                }            }            // Use interop to call the method necessary to clean up the unmanaged resource.            [System.Runtime.InteropServices.DllImport("Kernel32")]            private static extern bool CloseHandle(IntPtr handle);            /// <summary>            /// Finalizes an instance of the <see cref="MyResource"/> class.            /// Use C# destructor syntax for finalization code. This destructor will run only if the Dispose method does not get called. It gives your base class the opportunity to finalize.            /// Do not provide destructors in types derived from this class.            /// </summary>            ~MyResource()            {                // Do not re-create Dispose clean-up code here. Calling Dispose(false) is optimal in terms of readability and maintainability.                this.Dispose(false);            }        }    }}

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

Design Pattern IDisposable Pattern C相关推荐

  1. (?:pattern)与(?=pattern)的区别

    官方定义 (?:pattern) 匹配 pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用.这在使用 "或" 字符 (|) 来组合一个模式的各个部分 ...

  2. Design Pattern: Observer Pattern

    1. Brief 一直对Observer Pattern和Pub/Sub Pattern有所混淆,下面打算通过这两篇Blog来梳理这两种模式.若有纰漏请大家指正. 2. Use Case 首先我们来面 ...

  3. Design Pattern - Adapter Pattern

    适配器模式,超简单的一个设计模式. GOF的<设计模式>中解释如下: 将一个类的接口转换成客户希望的另外一个接口,Adapter使原本由于接口不兼容而不能一起工作的类可以一起工作 写个简单 ...

  4. Design Patterns - Mediator Pattern

    中介者模式用来封装一组对象的交互.以此让这些对象从本来的 紧密耦合到松耦合,让这些对象可以各自独立变化. 在一个GUI应用中, WinForm ,WebForm,ViewController都是一种M ...

  5. 正则表达式之?、(?:pattern)、(?!pattern)、(?=pattern)理解及应用

    今天朋友问我一个问题,是这样子的,通过正则表达式匹配html标签input包含hidden的字符串,具体如下: [java] view plain copy "<input type= ...

  6. java pattern.quote_Java Pattern quote(String)用法及代码示例

    Pattern类的quote(String)方法用于为作为参数传递给方法的指定String返回文字模式Pattern String.此方法产生一个等效于s的String,可用于创建Pattern.输入 ...

  7. python中的pattern什么意思_正则表达式中(?:pattern)、(?=pattern)、(?!pattern)、(?=pattern)和(?!pattern)...

    (?:pattern) ()表示捕获分组,()会把每个分组里的匹配的值保存起来,从左向右,以分组的左括号为标志,第一个出现的分组的组号为1,第二个为2,以此类推 (?:)表示非捕获分组,和捕获分组唯一 ...

  8. Problem Driven Pattern, Coaching Pattern Series

    无中生有 道生一, 一生二, 二生三, 三生万物 兵来将挡, 水来土掩 见招拆招 模式名称 问题驱动模式 意图 通过从问题出发引出实践, 而不是生搬硬套既有实践, 避免"强加给团队既有方案& ...

  9. Design Pattern----06.Creational.Singleton.Pattern (Delphi Sample)

    Intent Ensure a class has only one instance, and provide a global point of access to it. Encapsulate ...

最新文章

  1. mysql索引教程_MySQL教程96-MySQL索引类型
  2. 如何用JNI技术提高Java的性能详解
  3. 【Android】获取控件的宽和高
  4. vb不能插入png图片_第16节-图片 | 剑雨Axure RP9系列「基础」
  5. 混合模型简介与高斯混合模型
  6. (转)RabbitMQ学习之spring整合发送同步消息
  7. MySQL之创建表以及数据库增删改操作
  8. 彪悍语录系列(摘于网络)
  9. 新科LoRa网关和LoRa节点
  10. 编译LibreELEC.tv,报错: ld -lz can not find -lz,原来是zlib-1.2.11没有交叉编译
  11. 移动端适配:font-size设置方案的理解(浏览器调试移动端网页工具使用)
  12. 微信公众号绑定游戏中的安全问题
  13. QDateTime类
  14. jquery选择器通配符_jQuery选择器不等于通配符
  15. SAP外协采购单和销售单需求关闭预留未清处理方法
  16. 修改t3报表服务器,t3报表服务器配置
  17. B树和B+树傻傻分不清楚?
  18. DISTINCT和GROUP BY的区别
  19. 自然底数e的意义是什么?
  20. 基于qiankun落地部署微前端爬”坑“记

热门文章

  1. 推荐一款非常不错的子网计算器
  2. 克隆Calibrui Module
  3. 第八章 用户方式中线程的同步(2)
  4. CentOS 7 安装harbor1.5.0
  5. linux 查看剩余内存
  6. [开源]C#二维码生成解析工具,可添加自定义Logo
  7. printf-小代码,大问题
  8. 基于redis的悲观锁实现
  9. JVM(Java虚拟机)优化大全和案例实战
  10. alpine linux 执行文件崩溃 报错 找不到/lib/x86_64-linux-gnu/libc.so 解决方法