Click here to Skip to main content
12,067,351 members (56,619 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hi,

I am trying to get some values from array. I have declared like as shown below
public DataSetAnalog[] CalibPoints { get; private set; }
where DataSetAnalog is a class like this
public class DataSetAnalog
	{
		public double SetPoint { get; private set; }
		public double XValue { get; set; }
		public double YValue { get;	set; }
 
        public DataSetAnalog(double setPoint)
		{
			SetPoint = setPoint;
		}
 
		public override string ToString()
		{
			return SetPoint.ToString();
		}
	}
in one of the class i have the property like this
private DataSetAnalog[] _sensorData;
 
		public DataSetAnalog[] SensorData { get { return _sensorData; } private set { _sensorData = value; } }
and as well i am assigning values to "Calibpoints" like this
CalibPoints = _analogCalib.SensorData;


so finally i have tested elements in "CalibPoints" which has the format like this format

1 30 15656
2 60 24722
3 90 33782

like this. where 1,2,3 are setpoints and regarding x, y values or each set point.

I want to use that "CalibPoints" in some other method which display all values.
How can i access that?
I used for-loop but I am getting null always.

I have tried like this
if (sensor.Calibpoints != null)
           {
               for (int i = 0; i < sensor.Calibpoints.Length; i++)
                   _calib.polyPoints.Add(sensor.Calibpoints[i].XValue, sensor.Calibpoints[i].YValue);
           }
Posted 15-Apr-13 3:22am
Edited 15-Apr-13 4:24am
v4
Comments
du[DE] 15-Apr-13 8:26am
   
>I used for-loop but I am getting null always. @vebi: can you show please how do you do that? The code with your loop?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You don't show any code for assigning values to your CalibPoints property - as a result, since it is an array, and thus a reference type it's initial value will be null. Unless you later do something like:
CalibPoints = new DataSetAnalog[100];
you will never be able to use it.
  Permalink  
Comments
vebi1000 15-Apr-13 9:18am
   
Hi,
I am sorry for not posting required information. In one of the class i have like this
private DataSetAnalog[] _sensorData;

public DataSetAnalog[] SensorData { get { return _sensorData; } private set { _sensorData = value; } }
and as well i am assigning values to "Calibpoints" like this
CalibPoints = _analogCalib.SensorData;
vebi1000 15-Apr-13 9:25am
   
I have updated my question little bit more clearly....
OriginalGriff 15-Apr-13 9:28am
   
What have you got in _calib.polyPoints?
Have you had a look in the debugger?
vebi1000 15-Apr-13 9:36am
   
always if condition is failing so the code is not going inside if condition itself. While debugging i found that all points what ever i enter is storing in "Calibpoints". I am wondering at least how to print or show the elements in "Calibpoints" after that i can handle.
OriginalGriff 15-Apr-13 10:33am
   
Make up your mind which you are doing:
public DataSetAnalog[] CalibPoints { get; private set; }
or
public DataSetAnalog[] SensorData { get { return _sensorData; } private set { _sensorData = value; } }
Because if you are doing both, then
CalibPoints = _analogCalib.SensorData;
will still not assign any array space to either property - you need a new DataSetAnalog[100] or similar in there somewhere.
vebi1000 17-Apr-13 7:42am
   
Yes you are right, now i have solved it........i am very sorry for not providing the required information here.
OriginalGriff 17-Apr-13 7:45am
   
That's OK - glad you are sorted!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 15 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100