问题描述
我有几个数组来从postgreSQL查询中收集数据。数据来自现场部署的RF接收器。当用户建立查询的频率和时间范围时,数据显示在网格视图上并从那里传递到由I值指示的阵列和与包含RF接收器的纬度的列中的单元编号匹配的I +值。此数据用于绘制表示(频率,幅度),(频率,带宽)等的xy散点图。我想创建一个列表和对象而不是使用数组。
我的尝试:
I have several arrays to collect data from a postgreSQL query. The data comes from RF receiver deployed in the field. As the user establishes the range of frequencies and time for the query the data is displayed on gridview and passed from there to the arrays indicated by an I value and a I + value matching the cell number in the column containing the latitude of the RF receiver. This data is use to plot xy scatter graphs representing (frequency,amplitude), (frequency,bandwidth) etc. I would like to create a list and objects instead of using arrays.
What I have tried:
dataGridView1.SelectAll();
numCells = dataGridView1.SelectedCells.Count;
for (i = 14; i < (numCells); i += 14)
{
if (i < numCells)
{
if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.464258839)
{
UCS1size += 1;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.42859146)
{
MOCsize += 1;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.490616471)
{
AMsize += 1;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.525409911)
{
UCS2size += 1;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.560529988)
{
LC40size += 1;
}
}
else
{
MessageBox.Show("exiting for loop. numcells: " + numCells);
}
}
double[] freqLC40 = new double[LC40size];
double[] ampMaxLC40 = new double[LC40size];
double[] freqMOC = new double[MOCsize];
double[] ampMaxMOC = new double[MOCsize];
double[] freqUCS1 = new double[UCS1size];
double[] ampMaxUCS1 = new double[UCS1size];
double[] freqUCS2 = new double[UCS2size];
double[] ampMaxUCS2 = new double[UCS2size];
double[] freqAM = new double[AMsize];
double[] ampMaxAM = new double[AMsize];
int LC40idx = 0;
int MOCidx = 0;
int UCS1idx = 0;
int UCS2idx = 0;
int AMsidx = 0;
for (i = 14; i < (numCells); i += 14)
{
if (i < numCells)
{
if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.464258839)
{
freqUCS1[UCS1idx] = Convert.ToDouble(dataGridView1.SelectedCells[i].Value.ToString());
ampMaxUCS1[UCS1idx] = Convert.ToDouble(dataGridView1.SelectedCells[i + 9].Value.ToString());
UCS1idx += 1;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.42859146)
{
freqMOC[MOCidx] = Convert.ToDouble(dataGridView1.SelectedCells[i].Value.ToString());
ampMaxMOC[MOCidx] = Convert.ToDouble(dataGridView1.SelectedCells[i + 9].Value.ToString());
MOCidx += 1;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.490616471)
{
freqAM[AMsidx] = Convert.ToDouble(dataGridView1.SelectedCells[i].Value.ToString());
ampMaxAM[AMsidx] = Convert.ToDouble(dataGridView1.SelectedCells[i + 9].Value.ToString());
AMsidx += 1;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.525409911)
{
freqUCS2[UCS2idx] = Convert.ToDouble(dataGridView1.SelectedCells[i].Value.ToString());
ampMaxUCS2[UCS2idx] = Convert.ToDouble(dataGridView1.SelectedCells[i + 9].Value.ToString());
UCS2idx += 1;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[i + 11].Value.ToString()) == 28.560529988)
{
freqLC40[LC40idx] = Convert.ToDouble(dataGridView1.SelectedCells[i].Value.ToString());
ampMaxLC40[LC40idx] = Convert.ToDouble(dataGridView1.SelectedCells[i + 9].Value.ToString());
LC40idx += 1;
}
}
else
{
MessageBox.Show("exiting for loop. numcells: " + numCells);
}
}
//get XY form LC40
xyForm = new XYplotForm();
xyForm.Plot(freqLC40, ampMaxLC40, "LC-40 Max Amplitude");
xyForm.Show();
推荐答案
using System.Linq;
...
double[] array = new double[10];
List<double> list = array.ToList();
干杯
Andi
Cheers
Andi
double[] array = new double[10];
List<double> list = new List<double>(array);
这篇关于如何将数组转换为列表C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!