I'm trying to implement a data structure in C# 2.0 that could be represented like this:
| field1 | field2 | field3 | ... (variable length) ...
+--------+--------+--------+-------------------
1 | int0 | float0 | bool0 | ...
2 | int1 | float1 | bool1 | ...
. |
. |
. |
(variable) ...
Currently, I'm thinking on something really basic:
public class DataStructure {
string name;
List<string> fieldNames;
List<Item> items;
}
public class Item {
List<object> values;
}
Then, you could access with methods that implicitly define which type you're retrieving (i.e. bool GetBool (string field)
, int GetInteger (string field)
), so you work with a small set of built in types and custom clases (e.g. CustomBaseObject
).
Is there any existing data structure implementation that does this? Is this another (better) approach to solve the problem I'm presenting here? (Taking into account access & modification operation's complexity)
Also, I don't know what's the best way of boxing/unboxing the List<object> values
, if there's any other than just casting it like (type)values[index]
.