In-Memory Table Data structure

18,990

Solution 1

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.

Solution 2

Check DataTable class.

Solution 3

If you use .Net Framework 4.0 you can use Tuple!

Look here:

Tuple in C# 4.0

Solution 4

I'd imagine you probably want to use something like a List<Tuple<T1,T2,T3,T4>>

Solution 5

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

Share:
18,990
Steven
Author by

Steven

Updated on June 15, 2022

Comments

  • Steven
    Steven almost 2 years

    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)?

  • Steven
    Steven almost 13 years
    That was quick. Thanks. I used to think DataTable was meant only for database and stuff.
  • JohnLBevan
    JohnLBevan about 8 years
    Is there a concept of indexing / some way to improve querying on the collection for certain fields? My guess would be that you'd need to create Dictionaries with the key made up of the query fields and the results being a reference to the related underlying object; but that doesn't feel as clean as simply saying "this collection holds these objects; the properties I'd like to optimise for queries are these".