对于顺序数据,这是最好的;数组,数据集,数据表 [英] For sequential data, which is best; array, dataset, datatable

查看:64
本文介绍了对于顺序数据,这是最好的;数组,数据集,数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手。

我将从文件流中读取顺序数据。我将数据重新排序到表/数组并显示在主窗体上的DataView窗口中。数据将始终是顺序的。列是常量但行和表的数量不同,将在运行时确定。数据本质上是阵列/结构的阵列/结构。



我想将数据保存在内存中,以便快速加载到DataView中。



我应该使用数组,DataList,DataTables,DataSet,Collection?



我尝试过:



还没有,仍处于计划阶段。

解决方案

这里的数组是一个坏主意,除非你事先可以预测你将使用多少行 - 它们不可扩展。

同样的东西也可以应用于List - 它在内部使用一个数组并不断用一个更大的数组替换它,它被填充:列表< T> - 它是否真的像您想象的那样高效? [ ^ ]

他们都有可能的缺点,你需要创建一个类(或者struct)保存行的数据以便存储它。

数据集只是一个容纳相关DataTables的容器:如果你只有一组值,那么使用DataSet是没有意义的而不是DataTable。

DataList不是标准的C#类:它是HTML5规范的一部分。

那么......一个DataTable呢?好吧......也许。



它永远不会像总是使用这个那么简单 - 它将完全取决于你想要做什么。 DataTable是一个重型集合,有很多你可能不需要的行李 - 如果你所做的只是试图显示数据,那么它会给List带来更大的内存和性能足迹,但是这样做的好处是可以更容易地安排添加或删除运行时列。 List(或其他IEnumerable类)需要固定的公共属性结构才能直接显示列,并且在运行时很难更改。



但是......从用户的角度考虑显示:如果要显示的行数超过一百行,您需要查看分页,搜索和过滤,而不是仅仅将其转储到显示中并让用户把它排除在外 - 这比决定容纳数据的容器需要更多思考!


 DataSet,Collection 


I'm new to C#
I have sequential data I will read from a file stream. I will reorder the data into table/array and display in a DataView window on the main form. The data will always be sequential. The columns are constant but the number of rows and tables vary and will be determined at run time. The data is essentially array/structures of array/structures.

I want to hold the data in memory for quick loading into the DataView.

Should I use arrays, DataList, DataTables, DataSets, Collection?

What I have tried:

Nothing yet, still in planning stages.

解决方案

Arrays are a bad idea here, unless you can predict in advance how many rows you will be using - they are not expandable.
The same thing can also apply to List - it uses an array internally and continually replaces it with a bigger array wel it gets filled: List<T> - Is it really as efficient as you probably think?[^]
And both of them have the probable disadvantage that you would need to create a class (or struct) to hold the data for a row in order to store it.
A Dataset is just a container for holding related DataTables: if you only have one set of values, then it's pointless using a DataSet instead of a DataTable.
DataList is not a standard C# class: it's part of the HTML5 specification.
So...a DataTable it is then? Well ... maybe.

It's never as simple as "always use this" - it's going to depend on exactly what you are trying to do. A DataTable is a "heavy duty" collection, with a lot of "baggage" that you may not need - which gives it a lot heavier memory and performance footprint than a List would have if all you are doing is trying to display data, but with the advantage that it's a lot easier to arrange for run time columns to be added or removed. A List (or an other IEnumerable class) would need a fixed structure of public properties in order to display the columns directly, and that's very hard to change at run time.

But ... think about the display from the user point of view: if you have more than a hundred rows to display, you want to look at paging, searching, and filtering instead of just dumping it in the display and letting the user sort it out - and that takes a lot more thinking about than deciding what container to hold your data in!


DataSets, Collection


这篇关于对于顺序数据,这是最好的;数组,数据集,数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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