Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 95881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:43:39+00:00 2026-05-10T23:43:39+00:00

I found this question in an old question in your website so i thought

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:43:40+00:00Added an answer on May 10, 2026 at 11:43 pm

    You seem to be double-reading the lines, or maybe you’ve mixed up rows and cells – this bit in particular looks really odd:

            while ((line = rows.ReadLine()) != null)         {             String[][]rows = new String [i][]; ;             rows = rows.ReadLine();             String[][] rows = new string[S.Length][];             i++;         } 

    i.e. re-declaring rows, two calls to ReadLine per loop, etc. I suspect you mean string.Split? Either way, either use File.ReadAllLines, or look at some of the options presented yesterday. If you are desperate to use arrays, the core might look something like:

    using System; using System.IO; static class Program {     static void Main()     {         string[] lines = File.ReadAllLines('foo.txt');         string[][] grid = new string[lines.Length][];         for (int i = 0; i < lines.Length; i++)         {             grid[i] = lines[i].Split(',');         }          int totalCount = 0, maleCount = 0, femaleCount = 0,             m1Total = 0, m2Total = 0, m3Total = 0,             m1MaleTotal = 0, m1FemaleTotal = 0;         foreach (string[] line in grid)         {             totalCount++;             int m1 = int.Parse(line[3]),                 m2 = int.Parse(line[4]),                 m3 = int.Parse(line[5]);             m1Total += m1;             m2Total += m2;             m3Total += m3;             switch (line[1].Trim())             {                 case 'male':                     maleCount++;                     m1MaleTotal += m1;                     break;                 case 'female':                     femaleCount++;                     m1FemaleTotal += m1;                     break;             }         }         Console.WriteLine('Rows: ' + totalCount);         Console.WriteLine('Total m1: ' + m1Total);         Console.WriteLine('Average m1: ' + ((double)m1Total)/totalCount);         Console.WriteLine('Male Average m1: ' + ((double)m1MaleTotal) / maleCount);         Console.WriteLine('Female Average m1: ' + ((double)m1FemaleTotal) / femaleCount);     } } 

    Again – I cannot stress enough how much you should be doing this with LINQ instead of manual looping…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this similar question here , but this is really old. Was it
I found this question here: OLEDB v/s ODBC Which gave me more information, but
I found this question that is discussing what I would like to do, but
I found this question but it was only similar and, more importantly, dated by
I found this answer to this question https://stackoverflow.com/a/7244888/1473523 , but in my situation am
I've found this question on StackOverflow Adding div below images in colorbox But it
I haven't found this question, feel free to close if it's already up here.
I have found this question: What is the difference between @Inject and @EJB but
I've found this question asked several times when I've Googled for it, but the
Originally I wanted to ask this question , but then I found it was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.