Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   c# advice for csv files.. (http://www.programmingforums.org/showthread.php?t=13614)

teishu Jul 24th, 2007 5:48 AM

c# advice for csv files..
 
Hi, im writing a csv parser and was wondering what you think the best way of returnin the data is. its going to be a class that people can add to there projects. i was going to use arrays but then i remembered that you have to have set the size of the array before the app is compile so thats a problem.. How can i do you do you think ? The csv could have any amount of columns and any amount of lines...

xavier Jul 24th, 2007 5:51 AM

If the fixed size is the problem use : List<T> - it's the generic version of ArrayList. So that's that for the number of lines.

teishu Jul 24th, 2007 6:02 AM

Does it work like this ?

List<int> blah = new List<int>();
blah.Add(1);

xavier Jul 24th, 2007 6:06 AM

yeap.

teishu Jul 24th, 2007 6:09 AM

hmm, i take it i cant use it like this:

int totalcolumns = 5;
int count = 0;
while (count < totalcolumns)
{
List<int> count = new List<int>();
count++;
}



to have a list for each column...

teishu Jul 24th, 2007 6:57 AM

could i have a list of arrays ?

xavier Jul 24th, 2007 7:06 AM

you sure can. You can have a list of lists like :
List<List<string>> xxx = new List<List<string>>();
so xxx[0] will return a List<string>.(that would be one row from the file.)

Arla Jul 24th, 2007 9:13 PM

Personally I'd do it with ArrayList (when I say I'd do it with ArrayList, I mean that's what I did it with, I have both CSV pasers and CSV writers)

john Wesley Jul 24th, 2007 9:49 PM

I agree that a strong-typed list is not neccesary unless explicitly called for, an ArrayList also has a dynamic length.

You could however, as you are talking of above, use generics to keep track of the column and value, but I guess you already have a structure for matching up memorised values already.


All times are GMT -5. The time now is 2:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC