I found this question in an old question in your website so i thought i can do it but I think I was mistaken 🙂
the old post was here
I’m new at the jagged array thing so did the following code
StreamReader rows = new StreamReader('c:\\practice.txt'); string line; int i; i=1; while ((line = rows.ReadLine()) != null) { String[][]rows = new String [i][]; ; rows = rows.ReadLine(); String[][] rows = new string[S.Length][]; i++; } for (int i; i < S.Length; i++) { row[i] = S[I].Split(','); } int totalCounter = 0, totalSum = 0; // etc foreach(string[] row in rows) { int m1 = int.Parse(row[3]); totalCounter++; totalSum += m1; switch(row[2]) { case 'male': maleCount++; maleSum += m1; break; case 'female': femaleCount++; femaleSum += m1; break; } }
I know i did major mistakes but at east i tried can any one help me to make it a workin code
You seem to be double-reading the lines, or maybe you’ve mixed up rows and cells – this bit in particular looks really odd:
i.e. re-declaring rows, two calls to
ReadLineper loop, etc. I suspect you meanstring.Split? Either way, either useFile.ReadAllLines, or look at some of the options presented yesterday. If you are desperate to use arrays, the core might look something like:Again – I cannot stress enough how much you should be doing this with LINQ instead of manual looping…