A B C
A1 1 2 3
B1 4 5 6
C1 7 8 9
Using the above (like table) going to get the value for the given header value.
ex: if(column=” A” && row = “B1″) then value=”4”
without using a often if loops,Is there any idea to fetch the values using C#.
Note: The above is not a table or structure getting form DB or any memory objects .It is just a value mapping for the given headervalues.
The simplest solution would probably be to use a
Dictionary<Tuple<string, string>, int>, assuming you’re using .NET 4. It would work something like this:If you’re not using .NET 4 you could fake it by combining the row and column together, e.g. by concatenating them and adding a slash: “A/A1”, “B/B1” etc, and then having a
Dictionary<string, int>. It’s pretty ugly though – I’d be tempted to write my own RowColumn structure to avoid that.Another alternative would be to keep two dictionaries, each mapping row names or column names to indexes, and then an
int[,]array for the values. This has the benefit that you can identify when a row or column is invalid. If you really only have a few rows or columns, a simple list of strings would probably be just as fast or faster: