0
List<double> measurements = new List<double>();
double minimumx;
double maximumx;
double delta;
double actualValues;
//.
//.
//.
//.
//.Functionality of the above variables all stored as double
//.
//.
//.
//.

How do I store all the above double variables into the List "measurements"? Can I use List.AddRange(). Also eventually I am trying to call the measurements onto a different project in the same solution( basically create a viewmodel.cs file and call the "measurements" list there ) and plot the measurements using oxyplot.

user2864566
  • 71
  • 1
  • 1
  • 4
  • Why do you want to use [`AddRange`](http://msdn.microsoft.com/en-us/library/z883w3dc(v=vs.110).aspx)? ***What are you trying to do***? If you just want to store those variables, use `Add`. Are you trying to generate all the numbers in between the max and min? You'll need more than just `AddRange` to do that. In fact, with doubles it's impossible, because there are infinitely many Real numbers between a max and min. –  Apr 05 '14 at 22:15
  • Measurements.AddRange(new [] { minimumx, maximumx, delta, actualValues }); – Rand Random Apr 05 '14 at 22:17

2 Answers2

2

Create a class that has your four values in it and then have a list of that type of object. I assumed actualValues should also be a list.

public class Measurement
{
    public double MinimumX { get; set; }
    public double MinimumY { get; set; }
    public double Delta { get; set; }
    public IList<double> ActualValues { get; private set; }
    public Measurement() { this.ActualValues = new List<double>(); }
}

List<Measurement> measurements;
dav_i
  • 27,509
  • 17
  • 104
  • 136
FodderZone
  • 863
  • 12
  • 27
  • if he can encapsulate this in one class why he should using list – BRAHIM Kamel Apr 05 '14 at 22:18
  • Perhaps I read too much into his variables names. It seemed like a measurement would consist of actual values, a max value, a min value, and some sort of oscillation (perhaps called delta). These seemed a natural fit for encapsulation into one class. And if you are storing multiple instances of measurements, as I have understood them, then a List seems like a simple approach. – FodderZone Apr 05 '14 at 22:26
  • This is what I did measurements.Add(actualValues[j]); measurements.Add(minimumx); measurements.Add(maximumx); measurements.Add(delta); – user2864566 Apr 05 '14 at 22:31
  • 1
    Be careful with that approach. It will mean that you'll have to assume an order for the contents of your measurements List when reading data out. And when you add a set of measurement values you will have to add them in the same order everywhere in code. – FodderZone Apr 05 '14 at 22:38
1

You want to fill one list, and assume there will be always 4 elements in it?

You can add all these values to a list:

measurements.AddRange(new [] { minimumx, maximumx, delta, actualValues }); 

but I think this is bad idea.

You should create simple class or struct for that data, something like FodderZone suggested in another answer here.

Kamil
  • 13,363
  • 24
  • 88
  • 183