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 r开发者_如何学Pythoneading 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.
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.
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; }
}
}
精彩评论