I’m teaching myself to use Visual C# 2010 and I don’t know what data structure to use to store 3 columns of data from an Excel worksheet.
Column A contains person’s names (string), Column B contains person’s age (integer), and Column C contains person’s phone number (string). How do I store this into a data structure in C#?
In C++ I remember creating a vector that could hold a bunch of different data types…How do I do the equivalent in C#? I’ve read that vectors are not used in C#. Should I be using an array or list? Thanks.
The concept of a C++
vectoris roughly equivalent in functionality to the genericList<T>class in C#.As SLaks said, the best solution, given you know the types and that each set of three columns is a “row” in the table, is to create a simple class that holds your Column A, B, and C, then create a list of those:
If you’re using .NET 4 (which, since you’re using VS 2010, you should be), there’s a class
Tuple, which has several generic overloads and a static helper to create them:The upside is a built-in, flexible class; the downside is that a Tuple is very general-purpose and so its column names are similarly general-purpose; Item1, Item2, etc.