当前位置: 首页>>代码示例>>C#>>正文


C# SortedDictionary.Take方法代码示例

本文整理汇总了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();
		}
开发者ID:chantsunman,项目名称:Scutex,代码行数:27,代码来源:LicenseService.cs

示例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;
    }
开发者ID:quistador,项目名称:FOB,代码行数:29,代码来源:SupplyNetwork.cs


注:本文中的SortedDictionary.Take方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。