I'd like to create strongly typed collection for storing data in tables. is it possible?
Printable View
I'd like to create strongly typed collection for storing data in tables. is it possible?
Creating a strongly-typed collection is easy:That's all you need to get all the standard collection functionality. If you need custom behaviour then the Collection(Of T) class provides methods you can override to do that, plus you can add your own members.vb.net Code:
Public Class ThingCollection Inherits System.Collections.ObjectModel.Collection(Of Thing) End Class
That said, I have no idea what you mean by "for storing in tables". If the data is in a collection then what's the table for? Do you mean a database? Do you mean displaying to the user in a grid? Please provide a full and clear description up front in future. One sentence is rarely enough to convey the full picture to people who have no previous idea of what you're trying to achieve.
I mean collection like DataTable with some collumns, but I want it to be strongly typed. I want to use data from this collection without conversion.
Then all you need is a strongly-typed collection, as I've demonstrated. Your Thing class will have a property for each data item you want to store. Now, I've just used "Thing" and "ThingCollection" as examples. You would name your classes after whatever the items are supposed to represent.
thanks, i'll try to do it.