Reputation: 1243
I would like to build an in-memory table data structure with 4 columns so I can look up values based on any combination of the columns (using linq for example). Is there a built-in data type for this or do I have to craft one myself (obviously I can't)?
Upvotes: 9
Views: 22647
Reputation: 1064184
Unless you have something specific in mind, I would declare a type with 4 properties with suitable names and types, i.e.
public class SomethingSuitable {
public int Foo {get;set;}
public string Bar {get;set;}
public DateTime Blap {get;set;}
public float Blip {get;set;}
}
and use any list/array/dictionary etc as necessary, or just
data.Single(x => x.Bar == "abc");
etc.
Upvotes: 6
Reputation: 38230
You could use a DataTable
or even Populate a List<FourColClass>
which would adhere to the datatypes of your requirement. FourColClass
would be a class with properties as your columns.
Upvotes: 1
Reputation: 3621
I'd imagine you probably want to use something like a List<Tuple<T1,T2,T3,T4>>
Upvotes: 3
Reputation: 2919
You can use a DataTable object to do that. See: http://download.microsoft.com/download/5/8/6/5868081c-68aa-40de-9a45-a3803d8134b8/linq_over_dataset_for_csharp_developers.doc
Upvotes: 2
Reputation: 93090
How about simply:
var dataStructure = new[] {
new { col1 = "something", col2 = "something else", col3 = 12, col4 = true },
new { col1 = "ha", col2 = "ha ha", col3 = 356, col4 = false },
new { col1 = "grrr", col2 = "grr grr", col3 = 213, col4 = true }
};
Upvotes: 1