Its not the reading or writing the CSV file which is the issue it is I
cannot find an example of how to place data into a multi-demsendion
array and then how to get the data back out of the arral.
As far as I can see I must use an ArrayList so it can grow dynamically.
Regards
Jeff
- Show quoted text -
Jeff, others have given you great advice.
Here are some specifics that might help.
First, create a class to store each record from your csv. Something
like this:
public class Record
{
public Record(string field1, string field2, string field3) {
_field1 = field1;
_field2 = field2;
_field3 = field3;
}
private string _field1;
private string _field2;
private string _field3;
public void DoSomething() {
Console.WriteLine("{0}, {1} and {2}",
_field1, _field2, _field3);
}
}
As stated in the replies to your original message, the recommended
(and .NET 2.0+) approach is to use Generics (List<T> specifically).
List<Record> _myRecordsGen = new List<Record>();
// Create a list of Record objects. (You mentioned you had no
problem extracting
// data from your data source).
_myRecordsGen.Add(new Record("f1 of 1 (gen)", "f2 of 1 (gen)", "f3
of 1 (gen)"));
_myRecordsGen.Add(new Record("f1 of 2 (gen)", "f2 of 2 (gen)", "f3
of 2 (gen)"));
_myRecordsGen.Add(new Record("f1 of 3 (gen)", "f2 of 3 (gen)", "f3
of 3 (gen)"));
// Get your Record objects out of the list (and do something with
each).
foreach (Record record in _myRecordsGen) {
record.DoSomething();
}
You mentioned you think you might need to use an ArrayList. This is
true if you're using .NET 1.x. Here's the same example using an
ArrayList.
ArrayList _myRecordsAL = new ArrayList();
// Create a list of Record objects.
_myRecordsAL.Add(new Record("f1 of 1 (al)", "f2 of 1 (al)", "f3 of
1 (al)"));
_myRecordsAL.Add(new Record("f1 of 2 (al)", "f2 of 2 (al)", "f3 of
2 (al)"));
_myRecordsAL.Add(new Record("f1 of 3 (al)", "f2 of 3 (al)", "f3 of
3 (al)"));
// Get your Record objects out of the list (and do something with
each).
foreach (Record record in _myRecordsAL) {
record.DoSomething();
}
HTH
-Jay