存储表之类数据的最佳方法 [英] Best way to store table like data

查看:53
本文介绍了存储表之类数据的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储表之类的数据的最佳方法是什么:

What is the best way to store table like data like:

         | Column 0 | Column 1 | Column 2 | Column 3 | Column 4
Row 0    | 0.984546 | 0.654564 | 0.467676 | 0.673466 | 50.03333
Row 1    | 0.684546 | 0.457564 | 0.467776 | 0.674566 | 45.73335
Row 2    | 0.884546 | 0.424564 | 0.445676 | 0.664566 | 12.23333
Row 3    | 0.284546 | 0.054564 | 0.237676 | 0.124566 | 45.01333

最大列和最大行都是动态的,并且值的坐标非常重要,因为我必须基于这些值进行计算.它不是数据库,因为数据每次都不同,我不希望它永远存在.另外,我需要它易于访问.我尝试将 LinkedList Double [] 一起使用,但是对我来说很难找到每个值.速度也是一个因素.

Both max column and row is dynamic and the coordinates of the value is very important, as I have to do calculation based on those value. It's not a database because the data is different every time and I don't want it to be forever there. Also, I need it to be easily accessible. I try to use LinkedList with Double[] but it's just too difficult for me to locate each of the value. Speed is a factor too.

关于我应该使用的收藏类型或处理方式的任何建议吗?

Any suggestion on the type of collection I should use or ways to handle it?

推荐答案

我认为您应该声明此变量:

I think you should declare this variable:

List< List<double> > matrix = new List< List<double> >();

稍后,您可以使用 matrix.Capacity 来确定行数,并在每行上使用相同的属性来设置列数.这样您就不会浪费内存.

Later you can use matrix.Capacity to decide the number of rows and use that same property on each row to set the number of columns. This way you wont have memory wasted.

如果下一个数据会更短,则可以使用 matrix.TrimExcess()调整矩阵的大小.

You can use matrix.TrimExcess() to resize the matrix if your next data will be shorter.

使用 matrix.Capacity matrix.TrimExcess()的想法是控制数据结构中保留了多少空间.这样,它就不会自行增长,您将获得性能.

The idea behind using matrix.Capacity and matrix.TrimExcess() is to have control of how much space is reserved in the data structure. This way it wont grow by itself and you will gain performance.

这篇关于存储表之类数据的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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