本文整理汇总了C#中SortedDictionary.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.FirstOrDefault方法的具体用法?C# SortedDictionary.FirstOrDefault怎么用?C# SortedDictionary.FirstOrDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.FirstOrDefault方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateTilesByDistance
private void CalculateTilesByDistance() {
/// Only do this if we haven't already calculated it.
if (tilesByDistanceFromLeft != null) {
return;
}
Canvas.ForceUpdateCanvases();
tilesByDistanceFromLeft = new SortedDictionary<float, List<Transform>>();
foreach (Transform tile in tiles) {
RectTransform cellRect = GetTileCell(tile);
RectTransform tileRect = tile.GetComponent<RectTransform>();
/// Find how far this cell is from the left side of the layout.
Vector3 tilePoint = GetTilePoint(tileRect);
Vector3 worldPoint = cellRect.TransformPoint(tilePoint);
Vector3 layoutPoint = layoutTransform.InverseTransformPoint(worldPoint);
float distanceFromLeft = layoutPoint.x - layoutTransform.rect.xMin;
/// Add the tile into the appropriate group based on it's x position.
List<Transform> tilesAtDistance;
if (tilesByDistanceFromLeft.TryGetValue(distanceFromLeft, out tilesAtDistance)) {
tilesAtDistance.Add(tile);
} else {
/// See if their is already a tile group that exists
/// Within range of the TileGroupThreshold.
tilesAtDistance = tilesByDistanceFromLeft.FirstOrDefault(
pair => {
float distance = Mathf.Abs(distanceFromLeft - pair.Key);
return distance < kTileGroupThreshold;
}).Value;
/// Found a tile group within range.
if (tilesAtDistance != null) {
tilesAtDistance.Add(tile);
} else {
tilesAtDistance = new List<Transform>();
tilesAtDistance.Add(tile);
tilesByDistanceFromLeft[distanceFromLeft] = tilesAtDistance;
}
}
}
}
示例2: SmoothDictionaryLookup
//Take a dictionary of inflection points mapping a key to a value. Most often Beat is the key.
//Take a key and figure out which pair of dictionary entries it is between, and SmoothStep it between the values.
protected static float SmoothDictionaryLookup(SortedDictionary<float, float> phases, float key)
{
var previousPoint = phases.LastOrDefault(kvp => kvp.Key <= key);
var nextPoint = phases.FirstOrDefault(kvp => kvp.Key > key);
var duration = nextPoint.Key - previousPoint.Key;
var percentage = (key - previousPoint.Key) / duration;
return MathHelper.SmoothStep(previousPoint.Value, nextPoint.Value, percentage);
}
示例3: TryCreateOppositeOrder
private void TryCreateOppositeOrder(List<ExecutionMessage> retVal, SortedDictionary<decimal, RefPair<List<ExecutionMessage>, QuoteChange>> quotes, DateTime localTime, DateTimeOffset serverTime, decimal tradePrice, decimal volume, Sides originSide)
{
if (HasDepth(localTime))
return;
var oppositePrice = tradePrice + _settings.SpreadSize * GetPriceStep() * (originSide == Sides.Buy ? 1 : -1);
var bestQuote = quotes.FirstOrDefault();
if (bestQuote.Value == null || ((originSide == Sides.Buy && oppositePrice < bestQuote.Key) || (originSide == Sides.Sell && oppositePrice > bestQuote.Key)))
retVal.Add(CreateMessage(localTime, serverTime, originSide.Invert(), oppositePrice, volume));
}
示例4: CompatibleBuild
private static Tuple<SemanticVersion, string> CompatibleBuild(AssemblyReference assemblyDependency, SortedDictionary<Tuple<SemanticVersion, string>, DllReference> assemblies,
Tuple<SemanticVersion, string> resolvedAssembly)
{
var matchingAssembly = assemblies.FirstOrDefault(_ => _.Key.Item2.Equals(resolvedAssembly.Item2) && new Version(resolvedAssembly.Item1.Version.Major,resolvedAssembly.Item1.Version.Minor,resolvedAssembly.Item1.Version.Build).Equals(new Version(_.Key.Item1.Version.Major,_.Key.Item1.Version.Minor, _.Key.Item1.Version.Build)));
if (matchingAssembly.Key != null)
{
Trace.TraceWarning($"UPDATE : Not found in Cache : {assemblyDependency.Item2}, {assemblyDependency.Item1} Replaced by {matchingAssembly.Key.Item2}, {matchingAssembly.Key.Item1}");
resolvedAssembly = matchingAssembly.Key;
return resolvedAssembly;
}
return null;
}