I have a class that performs some operations on a set of data. The set of data to be processed is derived from a SQL query and usually consists of a few rows with 5 to 10 fields in the row. An example would be ..
"Bob", "Smith", "57", "555-555-5555", "Nursing"
"Pam", "Watson", "32", "555-555-3494", "Pre-Law"
"Sam", "Johnson", "42", "555-555-9382", "History"
"Paul", "Jenkins", "40", "555-555-3720", "Geography"
What is the best method to pass this data into a class? Or for that matter how about a method?
I want to make the class as generic as possible so I want to pass the data into it rather than have the class perform the data access necessary to get the data. Within the class I will need to be able to iterate through the data in order to perform some operation on it
I was initially thinking of passing in a dictionary object or a multi-dimensional array. I am looking to build the application in .NET. Thanks a bunch.
First, you should create a class to represent each row of the data; in this case
Studentlooks like a good fit:You should create and initialize one
Studentclass for each row of data. You can then add them to a collection class. AHashSet<Student>might be an appropriate choice:I haven’t gone into exact detail because I’m not sure how you are accessing the database.