Using C# I want to create one or more text files to store all the data pertaining to a particular 'Thing' on the same line. I am presently leaning towards StringBuilder as per the following.
sb.AppendFormat("{0}{1}{2}{3}{4}{5}{6}{7}"
, _ThingClass /* Thing class */
, _ClassType /* Property class type */
, _Prop0 /* These are generic properties that get manipulated depending on _ThingClass and _ClassType */
, _Prop1
, _Prop2
, _Prop3
, _Prop4
);
/*
Examples of _ThingClass (Person, Event, Vehicle, Item)
Examples of _ClassType (Teacher, Disaster, Car, Mobile Phone)
Examples of _Prop0-4 (Rachel, Tornado, Fiat, Samsung)
*/
The idea is to break down the string on a line to determine:
- What kind of Thing is stored on the line (first value), and
- How to handle the other fields* based on this value. (For example: Adding _Prop4 number value if a 'Heal' _ThingClass or Subtracting if a 'Harm' _ThingClass item, Perhaps even loading from, saving to a different text file so that the files can have only stuff of their own type (maybe easier for sorting).)
While I welcome any snippets of advice relating to this, I'll narrow down the question focus and ask:
Are there any cases where using a StringBuilder to structure data and save to or load from a file would be the way to go?
PS. I have found the content of "Which C# data structure should I use to quantify this information?" to be a possible alternative to StringBuilder - but I guess that there can be more than one valid path.