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

  • SEARCH
  • Home
  • 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 8276487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:23:20+00:00 2026-06-08T08:23:20+00:00

I need to loop this loop for all rows and not just the row

  • 0

I need to loop this loop for all rows and not just the row indexed by 2. Also I am getting an error in the double parsing.

Is there an efficient way to do the following?

The file can have variable lengths of rows. Thus I need to maintain an array to store the size of each row.

 public static void ReadFile()
    {
        int lineNo;
        List<List<double>> numbers = new List<List<double>>();
        foreach (string line in File.ReadAllLines("Data.txt"))
        {
            var list = new List<float>();
            foreach (string s in line.Split(new[]{',', ' '}, StringSplitOptions.RemoveEmptyEntries))
            {
                int i;
                if(double.TryParse(s, out i))
                {
                    list.Add(i);
                    lineNo++;
                }
            }
            numbers.Add(list);
        }

        var specialNumber = numbers[3][4];        // gives line 3 number 4
        var specialLine = numbers[2].ToArray();   //  gives an array of numbers of line 2

        double[] rowTotal;
        double[] squareRowTotal;
        double[] rowMean;

        //I need to loop this loop for all rows and not just the row indexed by 2. Also I am getting an error in the double parsing.

        for (int j=0; j<(specialLine.Length); j++)
        {
            rowTotal[2] = rowTotal[2] + numbers[2][j];
            squareRowTotal[2] = squareRowTotal[2] + numbers[2][j] * numbers[2][j];
        }

        for (int k = 0; k < lineNo; k++)
        {
            rowMean[k] = rowTotal[k] / numbers[k].Length;
        }
    }
  • 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. Editorial Team
    Editorial Team
    2026-06-08T08:23:22+00:00Added an answer on June 8, 2026 at 8:23 am
        public static void ReadFile()
        {
            List<List<double>> numbers = new List<List<double>>();
            foreach (string line in File.ReadAllLines(@"c:\temp\test.csv"))
            {
                var list = new List<double>();
                foreach (string s in line.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    double i;
                    if (Double.TryParse(s, out i))
                    {
                        list.Add(i);
                    }
                }
                numbers.Add(list);
            }
    
            double[] rowTotal = new double[numbers.Count];
            double[] squareRowTotal = new double[numbers.Count];
            double[] rowMean = new double[numbers.Count];
    
            for(int row = 0; row < numbers.Count; row++)
            {
                var values = numbers[row].ToArray();
    
                rowTotal[row] = values.Sum();
                squareRowTotal[row] = values.Select(v => v * v).Sum();
                rowMean[row] = rowTotal[row] / rowTotal.Count();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all need a lil help sorting a loop for this table out, cant
Okay so this is a bit complex but I need to loop through this
I have a thread containing a runnable. I need this to loop infinitely unless
I need to convert this for loop to a do while: for (int i
I need to write this program using a loop https://i.stack.imgur.com/gko6T.jpg this is what i
I need to run a loop in SQL. Google this is a little hard
I need to create a function that uses a loop. This function will open
I have a PHP script with infinite loop. I need this script running forever.
I need to loop over a query exactly 12 times to complete rows in
To start out with - this is not my code - there was a

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.