Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing 2 columns into a List

How can I store data from 2 columns (from a database) in a List

List<string> _items = new List<string>();

Any help is appreciated

like image 719
Cocoa Dev Avatar asked Dec 12 '11 16:12

Cocoa Dev


People also ask

Can a list have multiple columns?

A multi-column list is a very basic type of tabular Data Table that allows data to be arranged in columns.

How do I convert multiple columns to one column in Python?

DataFrames consist of rows, columns, and data. To combine the values of all the column and append them into a single column, we will use apply() method inside which we will write our expression to do the same. Whenever we want to perform some operation on the entire DataFrame, we use apply() method.


2 Answers

You create a class that will represent a row with 2 columns:

public class Foo
{
    // obviously you find meaningful names of the 2 properties

    public string Column1 { get; set; } 
    public string Column2 { get; set; }
}

and then you store in a List<Foo>:

List<Foo> _items = new List<Foo>();
_items.Add(new Foo { Column1 = "bar", Column2 = "baz" });
like image 89
Darin Dimitrov Avatar answered Oct 18 '22 09:10

Darin Dimitrov


Use a tuple struct like KeyValuePair

List<KeyValuePair<string, string>> _items = new List<KeyValuePair<string, string>>();
_items.Add(new KeyValuePair<string, string>(foo, bar));
like image 28
csharptest.net Avatar answered Oct 18 '22 09:10

csharptest.net