本文整理汇总了C#中SortedDictionary.Take方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.Take方法的具体用法?C# SortedDictionary.Take怎么用?C# SortedDictionary.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.Take方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLast10Licenses
public List<License> GetLast10Licenses()
{
var newLics = (from l in _licensesRepository.GetAllLicenses()
where l.UpdatedOn == null
orderby l.CreatedOn descending
select l).ToList();
var updatedLics = (from l in _licensesRepository.GetAllLicenses()
where l.UpdatedOn != null
orderby l.UpdatedOn descending
select l).ToList();
SortedDictionary<DateTime, License> sortedLics = new SortedDictionary<DateTime, License>();
foreach (var lic in newLics)
{
sortedLics.Add(lic.CreatedOn, lic);
}
foreach (var lic in updatedLics)
{
sortedLics.Add(lic.UpdatedOn.Value, lic);
}
return sortedLics.Take(8).Select(x => x.Value).ToList();
}
示例2: nearestNeighborNode
public List<int> nearestNeighborNode(Vector3 position, int numberOfNodes)
{
SortedDictionary<float,int> distanceToIdMap = new SortedDictionary<float, int>();
float minDistance = float.MaxValue;
// nearest neighbor search algorithms are numerous but intricate. We'll be
// sticking to a naive linear search for now.
foreach(int nodeKey in this.NetworkNodes.Keys)
{
SupplyNetwork.SupplyNode node = this.NetworkNodes[nodeKey];
// for purpose of finding the min distance, I'm assuming that we don't need to
// calculate d^2 = (x^2 + y^2). we'll try to avoid some calculations by computing
// d = x + y.
float simplifiedDistance =
System.Math.Abs(position.x - node.Position.x) +
System.Math.Abs (position.y - node.Position.y);
distanceToIdMap[simplifiedDistance] = nodeKey;
if(simplifiedDistance < minDistance)
{
minDistance = simplifiedDistance;
}
}
List<int> nearestIds = distanceToIdMap.Take(numberOfNodes).Select( kvp => kvp.Value ).ToList();
return nearestIds;
}