这是查找类:
public class DistanceAngle
{
public int distance;
public int distanceAngle;
public int valueOfBoth;
public static void getDisatnceAngleLookup()
{
List<DistanceAngle> distanceAngles = new List<DistanceAngle>
{
new DistanceAngle{distance = -5400, distanceAngle = -220, valueOfSideAngle = 320},
new DistanceAngle{distance = -5200, distanceAngle = -210, valueOfSideAngle = 290},
new DistanceAngle{distance = -5000, distanceAngle = -200, valueOfSideAngle = 200},
};
//Distance as Key Value and look for distanceAngle
Lookup<int, int> lookup = (Lookup<int, int>)distanceAngles.ToLookup((p => p.distance),
p => p.distanceAngle);
int count = lookup.Count;
// Select a collection of distanceAngles by indexing directly into the Lookup.
IEnumerable<int> cgroup = lookup[-5400];
// Output the results.
Console.WriteLine("\nPackages that have a key of 'C':");
foreach (int str in cgroup)
Console.WriteLine(str);
}
}
从界面上,如果用户A = 6000 B = 400 C = -5400
通过B-A
. 如果 C 值等于distance = -5400
LookUp calss 中的值,则获取该值distanceAngle = -220
并从 1 到 5 个单元格填充到 datagrid 特定列。
如果 C 值等于distance = -5400
并获取值valueOfSideAngle = 320
并填充到从 6 到 10 个单元格的数据网格特定列。
这样我可以获得列索引:datagridview1.Columns["columnName"].Index;
这是我正在执行计算的函数:
private void b_calculate_Click(object sender, EventArgs e)
{
int value1;
int.TryParse(t_LongitudeRadTextBox.Text, NumberStyles.Any,
CultureInfo.InvariantCulture.NumberFormat, out value1);
int value2;
int.TryParse(t_LongSecondaryRadTextBox.Text, NumberStyles.Any,
CultureInfo.InvariantCulture.NumberFormat, out value2);
var value3 = value2 - value1;
}
如何从查找表中获取等于value3
并填充到 datagridview 的值。任何帮助...!