views:

1849

answers:

3

I have some data I want to work with. Two string and two numbers and I have say 8000 rows of data.

Is a dataset the best option here to use, or could I use a struct and have a list of structs?

Would there be much performance difference between the list and the dataset?

A: 

Depends on what "work with" means to you. If I were displaying the data in a DataGridView or some other control such as that, I'd opt for the DataSet/DataTable route. Provides you with the ability do some easy filtering of the data.

Again, the performance difference of the List versus the DataSet depends on what you are doing. Lists are great for iterating through the container and things of that nature. DataSets and DataTables provide for easy operations such as ReadXML() (assuming you've got your data in XML, of course) that will take your elements, create columns and fill in the rows for you. That's pretty convenient.

Unless you are running on pretty restrictive hardware or have a lot else going on by other threads/processes, 8000 items isn't really a terribly large amount of data. I'd choose my container based on what I planned to do with it. If I were using databinding, I'd opt for the DataSet.

itsmatt
You can use Generic Lists to feed GridViews - this is not an advantage for DataSets/Tables.
Mark Brittingham
Agree that you can do this but depending on his needs, the DataTable solution might provide more flexibility over the list. The OP wasn't really clear, so it is hard to know for sure what's best. A lot of my data is pulled/pushed to a DB and those DataTables are darn convenient in my opinion.
itsmatt
+6  A: 

DataSets and DataTables are often more verbose and have some overhead to access, but usually are interoperable with whatever data-binding sort of stuff you're using.

If you have the choice (i.e. you're not hooked to some component that uses DataTables) I'd strongly suggest using an appropriate strongly-typed collection, like a generic List, Dictionary, or SortedDictionary. I propose that the flexibility and transparency will benefit you in the long run, if there is a long run to your project.

P.S. Two strings and two numbers is big enough that I doubt you'll see any benefit from making it a struct instead of a class. Of course, you should profile it for yourself, but that's my intuition. I agree with the post mentioning that you should be sure you understand the fundamental differences between the two if this is a case of premature optimization.

mquander
The two strings and two numbers was just an example. My actual data has 35 uints and 5 strings, still not a lot.
ghost
While my question was not ideal using a generic list is the method I am using now. Thanks all for the advice!
ghost
+3  A: 

Ok, I'm extrapolating based on limited data, but the fact that you are asking between a list of structs and a dataset implies to me that you're somewhat new to C# and have not been introduced to the fact that a struct is a ValueType and therefore lives on the stack. You have probably heard that a struct grants you "better performance" somewhere, and want to get the best performance you can for your list of 8000 items.

First, I believe that you are prematurely optimizing. Don't. Do whatever works within the scope of your program. If you are building this list of 8000 items yourself programmatically, perhaps from an XML or flat file, I'd suggest you use a list of objects, as that will be the easiest for you to program against. Your post does not imply that you have a relationship between two tabular sets of data, so a DataSet would be unnecessary.

That said, if you are receiving that list from the database somehow, and your current data layer is ADO.NET 2.0 (and therefore returns DataSets and DataTables), then I'd say use that. If you are receiving the list from the database but your data layer is not yet defined, I would suggest you look into LINQ to SQL or Entity Framework.

Again, I caution you against prematurely optimizing, especially given that you don't appear to understand how structs work. Again this is an assumption and I apologize in advance if I am wrong.

Randolpho
+1 - Nicely stated
Mark Brittingham
Sorry when I was talking about performance I did not really mean optimization. I was more curious if there were reasons not to use a generic list of a struct over a dataset. Thinking there is a large overhead using a dataset.
ghost
Though after reading up on stack vs heap again it makes perfect sence I should have been asking about a generic list of classes vs dataset.
ghost