如何访问数组中的元素。 [英] how to access elements in an array.

查看:73
本文介绍了如何访问数组中的元素。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想从数组中获取一些值。我已声明如下所示

Hi,

I am trying to get some values from array. I have declared like as shown below

public DataSetAnalog[] CalibPoints { get; private set; }



其中DataSetAnalog是这样的类


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; } }



以及我正在为这样的Calibpoints分配值


and as well i am assigning values to "Calibpoints" like this

CalibPoints = _analogCalib.SensorData;







所以最后我测试了CalibPoints中的元素,其格式类似于这种格式



1 30 15656

2 60 24722

3 90 33782



喜欢这个。其中1,2,3是设定值,关于x,y值或每个设定点。



我想在其他显示所有方法的方法中使用CalibPoints值。

我怎样才能访问它?

我用于循环但是我总是变空。



我试过这样的话




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);
           }

推荐答案

您不会显示任何为您的CalibPoints属性赋值的代码 - 如结果,因为它是一个数组,因此它的引用类型的初始值将为null。除非您稍后执行以下操作:

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];

你永远无法使用它。


这篇关于如何访问数组中的元素。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆