C#.Net中的数据集 [英] Dataset in c# .Net

查看:61
本文介绍了C#.Net中的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下2种情况之间有什么区别

1)Dataset ds = new Dataset();
Dataadapter.fill(ds,"emp");

2)数据集ds;
Dataadapter.fill(ds,"emp");

在方案1中,使用new关键字创建了数据集对象并使用了该对象.在方案2中,创建数据集对象时不使用new关键字.

b/w 2个场景有什么区别.在内存方面还是其他任何东西……


谢谢大家.

what is difference between below 2 scenarios

1)Dataset ds= new Dataset();
Dataadapter.fill(ds,"emp");

2)Dataset ds;
Dataadapter.fill(ds,"emp");

in scenario 1 created dataset object with new keyword and used that that object. In scenario 2 created dataset object with out using new keyword.

Is there any difference b/w 2 scenarios.memorywise or anything......


Thanks All.

推荐答案

这是程序员常犯的错误.

在第一种情况下,首先为数据集分配内存.在调用fill方法的那一刻,数据集对象将获得对填充数据的新数据集的引用.垃圾收集器清除第一行分配的内存.

在第二种情况下,没有进行这种内存分配,因此可以称为有效代码.
This is a common mistake done by programmers.

In the first case firstly memory is allocated for dataset. The moment you call the fill method, dataset object is given reference to a new dataset filled with data. garbage collector clears memory allocated in first line.

In second case no such memory allocation is done so can be called as efficient code.


是的,当然可以.在第一种情况下,您创建了一个数据集,然后将其替换为由Fill方法创建的数据集.在现实世界中,这没什么大不了,但是效率却较低.
Yes, of course. In the first scenario you created a dataset which was then replaced by the dataset created by the Fill method. In the real world, it''s not a big deal, but it''s less efficient.


除了这两个没有什么区别
there is no difference other than these two


这篇关于C#.Net中的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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