我有一个double[,]
,我想为此double[,]
的每一行创建一个列表,然后创建此列表的列表。我尝试了这段代码,但在lQC[j].Add(new double());
double[,] disQC = new double[42, TTools.Depth.Count];
List<double> mQC = new List<double>();
mQC.Add(new double());
for (int j = 0; j < Example.Count; j++)
{
mQC.Add(100);
for (int i = 0; i < 42; i++)
{
if (XQuartz[i] < TPorosity.Neutron[j] && TPorosity.Neutron[j] < XCalcite[i] && YQuartz[i] < TPorosity.BulkDensity[j] && TPorosity.BulkDensity[j] < YCalcite[i])
{
mQC[i] = (YCalcite[i] - YQuartz[i]) / (XCalcite[i] - XQuartz[i]);
disQC[i, j] = (Math.Abs((TPorosity.BulkDensity[j] - YQuartz[i] - (mQC[i] * TPorosity.Neutron[j]) + (mQC[i] * XQuartz[i])) / Math.Sqrt(Math.Pow(mQC[i], 2) + 1)));
}
else
{
disQC[i, j] = 100;
}
List<List<double>> lQC = new List<List<double>>();
lQC.Add(new List<double>());
lQC[j].Add(new double());
lQC[j].Add(disQC[i, j]);
List<int> MinimumIndexQC = new List<int>();
MinimumIndexQC.Add(80000);
MinimumIndexQC[j] = lQC[j].IndexOf(lQC[j].Min());
}
}
希望任何人都可以帮助我!
答案 0 :(得分:4)
在insert into run(id,name,dob)values(&id,'&name',TO_DATE('&dob','YYYY-MM-DD'));
语句的每次迭代中,您都会创建一个新的for
。在lQC
之前移动它。
答案 1 :(得分:0)
这是正确的解决方案。 Demo
public class Program {
public static void Main()
{
double[,] disQC = new double[5, 5];
List<List<double>> lQC = new List<List<double>>();
for (int j = 0; j < 5; j++) {
lQC.Add(new List<double>());
for (int i = 0; i < 5; i++) {
if (i % 2 == 0){
disQC[i, j] =i + 1 ;
}
else{
disQC[i, j] = j + 1;
}
lQC[j].Add(disQC[i, j]);
}
}
lQC.ForEach(l => { l.ForEach(t => Console.Write(t)); Console.WriteLine(""); });
}
}