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 4082552
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:12:06+00:00 2026-05-20T18:12:06+00:00

I have two list that I convert them to a single two dimesnional array

  • 0

I have two list that I convert them to a single two dimesnional array like this:

double[,] data = new double[voltage.Count(), 2];
for (int i = 0; i < voltage.Count(); i++)
{
    data[i, 0] = voltage[i];
    data[i, 1] = current[i];
}

Now I am trying to itterate through this array but what I get is same value for both voltage and current in each line:

foreach (double data in ztr.GetCurveDataForTestType()) //this will return my array
{
    richTextBox1.AppendText("Voltage" + data + "    ---------    ");
    richTextBox1.AppendText("Current" + data + "\r\n");
}

Voltage-0.175 ——— Current-0.175
Voltage-9.930625E-06 ——— Current-9.930625E-06
Voltage-0.171875 ——— Current-0.171875
Voltage-9.53375E-06 ——— Current-9.53375E-06
Voltage-0.16875 ——— Current-0.16875

As you see in the first line both voltage and current are same value that is voltage, and on the second raw they are the same again but this time it is the current value. How can I fix this?

  • 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-05-20T18:12:07+00:00Added an answer on May 20, 2026 at 6:12 pm

    I’d recommend not using multi-dimensional arrays for this.

    Instead you can make a class something like this:

    class Measurement
    {
        public double Voltage { get; set; }
        public double Current { get; set; }
    }
    

    And change your method to return IEnumerable<Measurement>. In .NET 4.0 you can use Zip:

    public IEnumerable<Measurement> GetCurveDataForTestType()
    {
        return voltage.Zip(current,
            (v, c) => new Measurement { Voltage = v, Current = c});
    }
    

    And for older versions of .NET:

    public IEnumerable<Measurement> GetCurveDataForTestType()
    {
        for (int i = 0; i < voltage.Count(); i++)
        {
            yield return new Measurement
            {
                Voltage = voltage[i],
                Current = current[i]
            };
        }
    }
    

    Then your code becomes:

    foreach (Measurement data in ztr.GetCurveDataForTestType())
    {
        richTextBox1.AppendText(
            "Voltage: {0} ---------  Current: {1}", data.Voltage, data.Current);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of strings that are all early modern English words ending
This is a C# winforms app. Preface: I am creating a form that will
I have two classes: a base class (Animal) and a class deriving from it
I have two classes A and B , and an implicit conversion operator exists
I need to convert a String representation of a nested List back to a
I have a linq statement which calls a stored proc and returns a list
I have an EF model that I'm passing into the views to Create and
There's an XML scheme which says something like this: <ExtraFields> <ExtraField Type=Int> <Key>Mileage</Key> <Value>500000
I have a map that I need to map to a different type, and
I have two classes named BaseCatalog and City. BaseCatalog is the parent class of

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.