Steven
Steven

Reputation: 1243

In-Memory Table Data structure

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

Answers (8)

Incognito
Incognito

Reputation: 16597

Check DataTable class.

Upvotes: 4

Marc Gravell
Marc Gravell

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

V4Vendetta
V4Vendetta

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

Dave
Dave

Reputation: 3621

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

Upvotes: 3

Petar Ivanov
Petar Ivanov

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

danyolgiax
danyolgiax

Reputation: 13116

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

Look here:

Tuple in C# 4.0

Upvotes: 3

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56222

See DataTable

Upvotes: 2

Related Questions