基于C#文本比较的设计方法

发布于 2024-10-25 06:57:46 字数 239 浏览 1 评论 0原文

我有一个 C# 项目,需要从一些文本文件中读取一些网格数据(两列,由可变数量的行形状数据组成),并在它们之间执行一些数学比较。你们认为在数据结构和设计方面表示这一点的最佳方法是什么?

样本数据表: 标签A:值A LabelB:ValueB

我正在考虑将所有数据读入 sqlite 数据库,然后使用查询使用 LINQ 对它们进行逐行比较?与将所有内容都放在内存数据结构中相比,您如何看待这个想法?如果还有其他想法,也请大声说出。谢谢。

I have a C# project whereby I need to read some grid data (two columns by variable number of rows-shaped data) from some text files and perform some mathematical comparisons across them. What do you guys feel is the best approach to represent this in terms of data structures and design?

Sample data table:
LabelA: ValueA
LabelB: ValueB

I was thinking about reading all of the data into a sqlite database and then using queries to do a row by row comparison against them using LINQ? What do you think of this idea vs having everything just in in-memory data structures ? If there are other ideas, please shout them out as well. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑脸一如从前 2024-11-01 06:57:48

我不会坚持它,除非将来完全有必要访问这些数据以避免重新处理所有内容。

我永远不会仅使用数组来实现此目的,我会构造一个对象来封装所有这些比较的逻辑。

我会简单地这样开始;

public class ImportedFile
{
    private List<FileLine> lines;
    public List<FileLine> Lines
    {
        get { return new ReadOnlyCollection(lines); }
    }

    public void AddLine(FileLine fl)
    {
        this.lines.Add(fl);
    }

    public void RemoveLine(FileLine fl)
    {
        this.lines.Remove(fl);
    }

    //Instance methods for comparing lines within the same file
    //Static methods for comparing Files
}

public class FileLine
{
    private String labelA;
    public String LabelA
    {
      get { return labelA; }
      set { labelA = value; }
    }

    private String labelB;
    public String LabelB
    {
      get { return labelB; }
      set { labelB = value; }
    }
}

I would not persist it, unless it is totally necessary to access this data in the future avoiding re-processing everything.

I would never use just an array for this, I would construct an object in order to encapsulate the logic for all this comparisons.

I would simply start this way;

public class ImportedFile
{
    private List<FileLine> lines;
    public List<FileLine> Lines
    {
        get { return new ReadOnlyCollection(lines); }
    }

    public void AddLine(FileLine fl)
    {
        this.lines.Add(fl);
    }

    public void RemoveLine(FileLine fl)
    {
        this.lines.Remove(fl);
    }

    //Instance methods for comparing lines within the same file
    //Static methods for comparing Files
}

public class FileLine
{
    private String labelA;
    public String LabelA
    {
      get { return labelA; }
      set { labelA = value; }
    }

    private String labelB;
    public String LabelB
    {
      get { return labelB; }
      set { labelB = value; }
    }
}
夜无邪 2024-11-01 06:57:47

如果它只是临时的,我认为没有理由增加数据库的开销。只需将其存储在内存中即可。二维数组似乎是最明显的数据结构,除非您有数组不能完全满足的特定要求。

If it's only temporary, I see no reason to add the overhead of a database. Just store it in memory. A two-dimensional array seems the most obvious data structure, unless you have specific requirements that are not fully satisfied with an array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文