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


C# Queue.Select方法代码示例

本文整理汇总了C#中System.Collections.Queue.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Select方法的具体用法?C# Queue.Select怎么用?C# Queue.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Queue的用法示例。


在下文中一共展示了Queue.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Get

        public IEnumerable<MsgItem> Get(Guid? id)
        {
            Queue<MsgItem> msgs;
            try
            {
                msgs = cache.Get<Queue<MsgItem>>(MsgKey) ?? new Queue<MsgItem>();
            }
            catch (Exception)
            {

                msgs = new Queue<MsgItem>();
            }

            //判断当前请求Id在不在缓存对列中
            //if (msgs.AsEnumerable<MsgItem>().Where(m => m.Id == id).Count() > 0)
            int index = (id == null) ? -1 : msgs.Select(m => m.Id).ToList().IndexOf(id.Value);
            if (index != -1)
            {

                return msgs.Skip(index + 1).Take(50 - index).AsEnumerable();
            }
            //不在则返回缓存中最新的10条记录
            else
            {
                int _startIndex = msgs.Count <= DefaultMsgLength ? 0 : msgs.Count - DefaultMsgLength;
                return msgs.Skip(_startIndex).Take(DefaultMsgLength).AsEnumerable();
            }
        }
开发者ID:ok-daker,项目名称:daker,代码行数:28,代码来源:MsgHandler.cs

示例2: BalanceIntakes

        private void BalanceIntakes()
        {
            Queue<Part> intakeQueue = new Queue<Part>( _editor.ship.Parts.Where( x => GetPartType( x ) == PartType.Intake ) // do not treat intakeandengine parts as intake but as engine
                .OrderByDescending( x => x.Modules.OfType<ModuleResourceIntake>().First().area ) ); // queue is easier to handle when distributing items to engines - this makes sure we can only handle a part once

            Utils.Log( "Intakes found: {0}", string.Join( ", ", intakeQueue.Select( x => x.partInfo.title + ": " + x.Modules.OfType<ModuleResourceIntake>().First().area ).ToArray() ) );
            List<WeightedPartList> totalPartList = new List<WeightedPartList>();
            // so far all jets have intakeair ratio of 15, so we treat jets, turbos and rapiers alike
            // TODO for future: take intakeair ratio into account. how exactly? I donno :)

            // handle engines grouped by type, so far its by placement order
            foreach ( Part part in _editor.ship.parts )
            {
                if ( GetPartType( part ) == PartType.AirBreatherEngine )
                {
                    WeightedPartList wpl = new WeightedPartList();
                    wpl.AddPart( part );
                    totalPartList.Add( wpl );
                }
                else if ( GetPartType( part ) == PartType.IntakeAndEngine )
                {
                    WeightedPartList wpl = new WeightedPartList();
                    wpl.IntakeAreaSum = part.Modules.OfType<ModuleResourceIntake>().First().area; // add intake area of part that has both intake and engine in one
                    wpl.AddPart( part );
                    totalPartList.Add( wpl );
                }
            }

            Utils.Log( "Jets found: {0}", string.Join( ", ", totalPartList.Select( x => x.PartList.First().partInfo.title ).ToArray() ) );

            if ( intakeQueue.Count > 0 && totalPartList.Count > 0 )
            {
                // strip ship from intakes and jets
                _editor.ship.parts.RemoveAll( x => intakeQueue.Contains( x ) );
                Utils.Log( "removed intakes temporarily" );
                _editor.ship.parts.RemoveAll( x => totalPartList.Select( y => y.PartList.First() ).Contains( x ) );
                Utils.Log( "removed jets temporarily" );

                int intakeCount = intakeQueue.Count;
                for ( int i = 0; i < intakeCount; i++ )
                {
                    Part part = intakeQueue.Dequeue();
                    totalPartList.Where( x => x.IntakeAreaSum == totalPartList.Min( y => y.IntakeAreaSum ) ).First().AddPart( part ); // WeightedPartList with the least IntakeAreaSum will get the next intake assigned
                }

                // go through all part lists, reverse them and add them back to ship
                foreach ( WeightedPartList partList in totalPartList )
                {
                    partList.PartList.Reverse();
                    _editor.ship.parts.AddRange( partList.PartList ); // add parts for engine and its intakes back to ship
                    Utils.Log( "Intake/engine set: {0}, total intake area: {1}", string.Join( ", ", partList.PartList.Select( x => x.name ).ToArray() ), partList.IntakeAreaSum );
                }

                Utils.Log( "Finished intakes - jets balance" );
            }
            else
            {
                Utils.Log( "There are either no intakes or no engines" );
            }
        }
开发者ID:shepheb,项目名称:KSP,代码行数:60,代码来源:IntakeBuildAid.cs


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