static DataTable getDataTable()
        {
            "))
            {
                SqlCommand com = new SqlCommand("", con);
                SqlDataAdapter sda = new SqlDataAdapter(com);
                using (DataTable dt = new DataTable())
                {
                    sda.Fill(dt);
                    return dt;
                }
            }
        }

Reflector 反编译后

private static DataTable getDataTable()
{
    DataTable table2;
    "))
    {
        SqlCommand selectCommand = new SqlCommand("", connection);
        SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
        using (DataTable table = new DataTable())
        {
            adapter.Fill(table);
            table2 = table;
        }
    }
    return table2;
}

  private static DataTable getDataTable()
{
    DataTable table2;
    "))
    {
        SqlCommand selectCommand = new SqlCommand("", connection);
        SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
        using (DataTable table = new DataTable())
        {
            adapter.Fill(table);
            table2 = table;
        }
    }
    return table2;
}

using 中写 return  一样会释放using 中对象 但是会在外面定义一个一样的对象 赋值后 释放 最后 return 外面定义的那个对象

using 中写 return 一样会释放using 中对象 但是会在外面定义一个一样的对象 赋值后 释放 最后 return 外面定义的那个对象的更多相关文章

  1. jquery中定义数组并给数组赋值后转为json格式为[]问题的解决

    一.问题描述:jquery定义一个空数组,并赋值,结果转为json格式后打印值为空 我原本是这样写的,但是show_data值一直为[] var export_data = [];export_dat ...

  2. oracle调用java方法的例子(下面所有代码都是在sql/plus中写)

    在Oracle中调用Java程序,注意:java方法必须是static类型的,如果想在JAVA中使用system.out/err输出log. 需要在oracle 中执行"call dbms_ ...

  3. Linux启动kettle及linux和windows中kettle往hdfs中写数据(3)

    在xmanager中的xshell运行进入图形化界面 sh spoon.sh 新建一个job

  4. DirectShow中写push模式的source filter流程 + 源代码(内附详细注释)

    虽然网上已有很多关于DirectShow写source filter的资料,不过很多刚开始学的朋友总说讲的不是很清楚(可能其中作者省略了许多他认为简 单的过程),读者总希望看到象第一步怎么做,第二步怎 ...

  5. DirectShow中写push模式的source filter流程 + 源码(内附具体凝视)

    尽管网上已有非常多关于DirectShow写source filter的资料.只是非常多刚開始学的朋友总说讲的不是非常清楚(可能当中作者省略了很多他觉得简 单的过程).读者总希望看到象第一步怎么做,第 ...

  6. 在mybatis中写sql语句的一些体会

    本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...

  7. 【Filter 不登陆无法访问】web项目中写一个过滤器实现用户不登陆,直接给链接,无法进入页面的功能

    在web项目中写一个过滤器实现用户不登陆,直接给链接,无法进入页面,而重定向到登陆界面的功能. 项目是用springMVC+spring+hibernate实现 (和这个没有多大关系) 第一步: 首先 ...

  8. python中写shell(转)

    python中写shell,亲测可用,转自stackoverflow To run a bash script, copy from stackoverflow def run_script(scri ...

  9. Android 手写Binder 教你理解android中的进程间通信

    关于Binder,我就不解释的太多了,网上一搜资料一堆,但是估计还是很多人理解的有困难.今天就教你如何从 app层面来理解好Binder. 其实就从我们普通app开发者的角度来看,仅仅对于androi ...

随机推荐

  1. 洛谷 P5461 赦免战俘

    洛谷 P5461 赦免战俘 传送门 思路 洛谷7月月赛第一题 着实是一道大水题,然后我月赛的时候没做出来...... 就是一道大模拟题呀,直接dfs就好了,我是反着处理的,所以最后要输出\(1-a[i ...

  2. 《Three js开发指南》 PDF

    电子版仅供预览及学习交流使用,下载后请24小时内删除,支持正版,喜欢的请购买正版书籍:<Three js开发指南> pdf下载地址:链接: https://pan.baidu.com/s/ ...

  3. 8.5 NOIP模拟测试13 矩阵游戏+跳房子+优美序列

    T1矩阵游戏 数学题.首先这一列这一行先乘还是后乘对最后答案没有影响.a[i][j]表示矩阵中原始的值,h[i]表示i行的累乘,l[i]表示i列的累乘.易得ans=Σa[i][j]*h[i]*l[i] ...

  4. [LeetCode] 236. Lowest Common Ancestor of a Binary Tree 二叉树的最小共同父节点

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  5. [LeetCode] 210. Course Schedule II 课程清单之二

    There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prereq ...

  6. 关于阻止百度滥用cookies的想法

    Chrome浏览器支持禁止指定的cookies,因此可以作为阻止百度滥用cookies的突破口,最好的方案应该是制作chrome插件(国内厂商的浏览器基本都是基于谷歌开源的 Chromium计划,基本 ...

  7. php和jquery生成QR Code

    php生产QR Code 下载qrcode源码,地址:https://sourceforge.net/projects/phpqrcode/files/releases/ 1.解压后引入qrlib.p ...

  8. 打造个人专属网盘nextcloud

    原文 https://edu.aliyun.com/course/150/lesson/list?spm=5176.9278281.815111.sence.114d4f3eLLMS53

  9. 从GopherChina 2019看当前的go语言

    GopherChina 2019大会4月底刚刚结束,大会上使用的PPT也放了出来(大会情况及PPT在https://mp.weixin.qq.com/s/_oVpIcBMVIKVzQn6YrkAJw) ...

  10. 慕课网springboot博客系统开发(一)----spring initializr的使用 gradle构建项目

    spring initializr工具的地址:https://start.spring.io/:通过它可以很方便的创建springboot项目 这里我们选择使用gradle作为项目的构建工具,此spr ...