I have a dictionary where I'm trying to find the max of a specific class value, similar to getting max of a list. I've been searching for a couple of hours but all I'm finding is how to grab a value from a dictionary that has a key and a single value. I've also come across Linq but I'm not finding anything on how to search a dictionary's class values for the Max value. I'm pretty sure there is a way and I'm just missing something?
In my case, I'm trying to find the Max lineDistance
of my class LineInfo
Links that I have found are close
this one but it only deals with a single key and a single value, not a class
this one seems like it might be on the right track but the checked answer suggests to run a nested foreach. I would imagine there's an easier / more sosphisticated way?
Any and all help is appreciated.
here is my code, it's fairly simple:
class LineInfo
{
public double lineDistance { get; set; }
public LineSegment2d lineSegment2D1 { get; set; }
public LineSegment2d lineSegment2D2 { get; set; }
}
var lines = new Dictionary<int, LineInfo>();
double pointDistance0 = lineSegment2DList[i].StartPoint.GetDistanceTo(lineSegment2DList[j].StartPoint);
lines.Add(0, new LineInfo {lineDistance = pointDistance0, lineSegment2D1 = lineSegment2DList[i], lineSegment2D2 = lineSegment2DList[j] });
double pointDistance1 = lineSegment2DList[i].StartPoint.GetDistanceTo(lineSegment2DList[j].EndPoint);
lines.Add(1, new LineInfo { lineDistance = pointDistance1, lineSegment2D1 = lineSegment2DList[i], lineSegment2D2 = lineSegment2DList[j] });
double pointDistance2 = lineSegment2DList[i].EndPoint.GetDistanceTo(lineSegment2DList[j].StartPoint);
lines.Add(2, new LineInfo { lineDistance = pointDistance2, lineSegment2D1 = lineSegment2DList[i], lineSegment2D2 = lineSegment2DList[j] });
double pointDistance3 = lineSegment2DList[i].EndPoint.GetDistanceTo(lineSegment2DList[j].EndPoint);
lines.Add(3, new LineInfo { lineDistance = pointDistance3, lineSegment2D1 = lineSegment2DList[i], lineSegment2D2 = lineSegment2DList[j] });