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


C# Queue.ToArray方法代码示例

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


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

示例1: DoTest

		public static void DoTest ()
		{
			string top;
			Queue<string> queue = new Queue<string>();

			queue.Enqueue("aaa");
			queue.Enqueue("bbb");
			queue.Enqueue("ccc");
			queue.Enqueue("ddd");
			queue.Enqueue("eee");
			queue.Enqueue("fff");
			queue.Enqueue("ggg");
			queue.Enqueue("hhh");

			Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());

			var array = queue.ToArray();
			Debug.Assert (array.Length == 8, "Wrong size.");

			queue.Pop();
			queue.Pop();
			top = queue.Dequeue();

			Console.WriteLine("Old 3nd-last: " + top + "\r\n");
			Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());

			queue.Pop();
			queue.Pop();

			Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());

			var array2 = queue.ToArray();
			Debug.Assert (array2.Length == 3, "Wrong size.");
		}
开发者ID:hjorturls,项目名称:C-Sharp-Algorithms,代码行数:34,代码来源:QueueTest.cs

示例2: ToArrayTest

		public void ToArrayTest()
		{
			var queue = new Queue();
			var array = queue.ToArray();

			Assert.AreEqual(0, array.Length);

			queue.Enqueue("No.1");
			queue.Enqueue("No.2");
			queue.Enqueue("No.3");

			array = queue.ToArray();
			Assert.AreEqual(3, array.Length);
		}
开发者ID:Flagwind,项目名称:Zongsoft.CoreLibrary,代码行数:14,代码来源:QueueTests.cs

示例3: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether GetEnumerator() is successful when the queue is not empty.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            for (int i = 0; i < TestQueue.Count; i++)
            {
                if (TestQueue.ToArray()[i] != TestEnumerator.Current)
                {
                    TestLibrary.TestFramework.LogError("P01.1", "GetEnumerator() failed when the queue is not empty!");
                    retVal = false;
                }
                TestEnumerator.MoveNext();
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:34,代码来源:queuegetenumerator.cs

示例4: Mine

        public void Mine()
        {
            var sequencesWithAtLeastKNodes = DataSet.SequentialData.Where(d => d.Count() > K - 1).ToList(); // all sequences of at least length k
            var distinctSequences = FilterRepeatedNavigations ? GetDistinctSequences(sequencesWithAtLeastKNodes)
                                                              : sequencesWithAtLeastKNodes;

            supportDenominator = 0;
            var tempRules = new Dictionary<string, int>();
            var navigationPattern = new Queue<char>(K);

            foreach (var nodeSequence in distinctSequences)
            {
                navigationPattern.Clear();
                foreach (var node in nodeSequence)
                {
                    navigationPattern.Enqueue(((char)(node + 64)));
                    if (navigationPattern.Count < K) continue;
                    addToDictionary(string.Join("", navigationPattern.ToArray()), tempRules, 1);
                    navigationPattern.Dequeue();
                    supportDenominator++;
                }
            }

            //remove candidate rules that do not have required support
            foreach (var supCount in tempRules.Where(supCount => supCount.Value / (double)supportDenominator >= MinimumSupport))
            {
                addToDictionary(supCount.Key, Rules, supCount.Value);
            }
            PrintRules();
        }
开发者ID:parrottsquawk,项目名称:School,代码行数:30,代码来源:KSequenceMiner.cs

示例5: DownloadScorecards

        private static void DownloadScorecards(FileStore dataStore, Season season)
        {
            CrawlResults crawlResults = GetCrawlResultsForSeason(dataStore, season);
            if (crawlResults == null)
            {
                Log.WarnFormat("Season {0} has not been crawled yet.", season.Name);
                return;
            }

            Log.InfoFormat("Scorecard download started at {0} for season {1}", DateTime.Now.ToShortTimeString(), crawlResults.Season);

            var matchRecords = crawlResults.Classifications.SelectMany(m => m.Scorecards);

            Queue<Task> tasks = new Queue<Task>();

            foreach (ScorecardDetails md in matchRecords)
            {
                if (md.ScorecardAvailable && !string.IsNullOrEmpty(md.ScorecardUrl))
                {
                    Log.InfoFormat("Downloading scorecard for {0}", md);

                    tasks.Enqueue(DownloadScorecardAsync(md, dataStore));
                }
            }

            Task.WaitAll(tasks.ToArray());

            SaveCrawlerResults(crawlResults, dataStore);

            Log.InfoFormat("Scorecard download finished at {0} for season {1}", DateTime.Now.ToShortTimeString(), crawlResults.Season);
        }
开发者ID:bugedone,项目名称:somerset,代码行数:31,代码来源:DownloadCommand.cs

示例6: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether Enqueue(T) is successful.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            if (TestQueue.Count != 3 || TestQueue.Peek() != "one" || TestQueue.ToArray()[2] != "three")
            {
                TestLibrary.TestFramework.LogError("P01.1", "Enqueue() failed!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:26,代码来源:queueenqueue.cs

示例7: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest2: Test whether ToArray() is successful when the queue is not empty.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            string[] TestArray = TestQueue.ToArray();
            if (TestArray.Length != 2)
            {
                TestLibrary.TestFramework.LogError("P02.1", "ToArray() failed! Element number in array and queue are not equal!");
                retVal = false;
            }
            if (TestArray[0] != "one" || TestArray[1] != "two")
            {
                TestLibrary.TestFramework.LogError("P02.2", "ToArray() failed! Elements in array are not the same as in queue!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P02.3", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:31,代码来源:queuetoarray.cs

示例8: Main

    static void Main()
    {
        var startNumber = int.Parse(Console.ReadLine());

        var queue = new Queue<int>();
        queue.Enqueue(startNumber);

        var member = 0;
        int[] startIndex;
        while (true)
        {
            queue.Enqueue(startNumber + 1);

            if (queue.Count == 50)
            {
                break;
            }

            queue.Enqueue((2 * startNumber) + 1);
            queue.Enqueue(startNumber + 2);

            startIndex = queue.ToArray();
            startNumber = startIndex[member + 1];
            member++;
        }

        foreach (var num in queue)
        {
            Console.Write(num + " ");
        }
    }
开发者ID:DimitarStoyanovVictory,项目名称:Data-Structures,代码行数:31,代码来源:CalculateSequenceWith.cs

示例9: EmitArrayInitializerExpression

        public EmitArrayInitializerExpression(EmitType type, EmitArrayInitializer initializer)
        {
            Type = type;
            Initializer = initializer;

            if (Initializer.Length == 0)
                throw new EmitVerifyException("An array initiaizler expression must have at least one element.");

            Rank = 0;
            var lengths = new Queue<int>();
            lengths.Enqueue(Initializer.Length);
            var current = Initializer[0];
            while (current != null)
            {
                Rank++;
                if (current is EmitArrayInitializer)
                {
                    lengths.Enqueue(current.Length);
                    current = current[0];
                }
                else
                {
                    current = null;
                }
            }
            Lengths = lengths.ToArray();
        }
开发者ID:kswoll,项目名称:sexy-emit,代码行数:27,代码来源:EmitArrayInitializerExpression.cs

示例10: GetEntityNames

        public Invocation[] GetEntityNames(string line)
        {
            var entities = new Queue<Invocation>();
            var stringWalker = new StringWalker();
            var startIndex = 0;

            line = line.Trim();

            foreach (var currentPosition in stringWalker.Iterate(line))
            {
                if (currentPosition.Character == ' ' && !stringWalker.StateIs(StringWalkerState.InsideString) && !stringWalker.StateIs(StringWalkerState.InsideParentheses))
                {
                    stringWalker.Abort();
                    return GetEntityNames(line.Substring(currentPosition.Index));
                }

                if (currentPosition.Character == '.' && stringWalker.HasNoState)
                {
                    Enqueue(entities, line.Substring(startIndex, currentPosition.Index - startIndex));
                    startIndex = currentPosition.Index + 1;
                }
            }

            Enqueue(entities, line.Substring(startIndex));

            return entities.ToArray();
        }
开发者ID:jagregory,项目名称:boolangstudio,代码行数:27,代码来源:LineEntityParser.cs

示例11: Main

        static void Main(string[] args)
        {
            int start = int.Parse(Console.ReadLine());
            var qResult = new Queue<int>();

            qResult.Enqueue(start);

            int n = 0;
            while (n <= 50)
            {
                qResult.Enqueue(start + 1);
                qResult.Enqueue(start * 2 + 1);
                qResult.Enqueue(start + 2);

                int[] nextStart = qResult.ToArray();
                start = nextStart[n + 1];

                n++;
            }

            for (int i = 0; i < qResult.Count; i++)
            {
                Console.Write(qResult.Dequeue() + ", ");
            }
            Console.WriteLine();
        }
开发者ID:Petar-Ivanov256,项目名称:DataStuctures_HomeWorks,代码行数:26,代码来源:SequenceQueue.cs

示例12: Split

        internal static CalculationOptions[] Split(CalculationOptions options, uint tasks)
        {
            Queue<CalculationOptions> t1 = new Queue<CalculationOptions>();
            Queue<CalculationOptions> t2 = new Queue<CalculationOptions>();

            t1.Enqueue(options);

            tasks = (uint)Math.Pow(4, Math.Ceiling(Math.Log(tasks) / Math.Log(4)));

            while (tasks > 0)
            {
                while (t1.Count > 0)
                {
                    CalculationOptions t = t1.Dequeue();
                    foreach (CalculationOptions spl in SplitInFour(t))
                    {
                        t2.Enqueue(spl);
                    }
                }
                tasks /= 4;
                t1 = t2;
                t2 = new Queue<CalculationOptions>();
            }

            return t1.ToArray();
        }
开发者ID:MrAksel,项目名称:FractalServer,代码行数:26,代码来源:RenderTaskHelper.cs

示例13: GetResponse

        /// <summary>
        /// 使用WebRequest發送請求並取得Response(有網站認證介面與Proxy的Uri設定)
        /// </summary>
        /// <param name="uriString">目的地Uri字串</param>
        /// <param name="method">Get/Post</param>
        /// <param name="sendData">null(Get)/bytes(Post)</param>
        /// <param name="errorMsg">異常輸出(default:"")</param>
        /// <param name="debugDisplay"></param>
        /// <param name="credential">認證用(default:null)</param>
        /// <param name="timeOut">請求的回應逾時(ms)</param>
        /// <param name="proxyString"></param>
        /// <param name="requestHeaders">新增請求Header資料</param>
        /// <returns>Response回應資料(Byte Array)</returns>
        public static byte[] GetResponse(string uriString, string method, byte[] sendData, out string errorMsg, ICredentials credential, int timeOut = 10000, NameValueCollection requestHeaders = null, bool debugDisplay = false, string proxyString = null)
        {
            #region variable
            WebRequest request = null;
            Stream dataStream = null;
            WebResponse response = null;
            byte[] result = null;
            Queue<byte> buffer = null;
            int readByte = -1;
            errorMsg = string.Empty;
            #endregion

            try
            {
                // 1.create request and setting timeout, credential, proxy(if has)
                request = CreateWebRequest(uriString, timeOut);
                // 2.set credential and proxy
                SetCredentialAndProxy(request, credential, proxyString);
                // 3.setting request method and send data(if has)
                SetReuqestHeaders(request, method, requestHeaders);

                // 4.Request data write to stream( if has data)
                if (!WriteRequestData(request, sendData, out errorMsg))
                {
                    throw new Exception(errorMsg);
                }

                // 5.等待並取得Server回應
                response = request.GetResponse();
                dataStream = response.GetResponseStream();

                // 檢視Request和Response內的屬性數據
                if (debugDisplay)
                {
                    ReflectionAllPropertyValue(request);
                    ReflectionAllPropertyValue(response);
                }
                buffer = new Queue<byte>();

                // 6.將Response的數據讀出並輸出
                while ((readByte = dataStream.ReadByte()) > -1)
                {
                    buffer.Enqueue((byte)readByte);
                }
                result = buffer.ToArray();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Response Error:" + ex.Message + "\n " + ex.StackTrace);
                //throw ex;
                errorMsg = "Response Error:" + ex.Message + "\n " + ex.StackTrace;
            }
            finally
            {
                // 6.關閉Response連線
                dataStream.Close();
                response.Close();
            }
            return result;
        }
开发者ID:knarf7112,项目名称:HttpClient_Lib,代码行数:73,代码来源:Client.cs

示例14: GameTips

        /// <summary>
        /// Create the default rotating game tip module
        /// </summary>
        public GameTips()
        {
            tips = TipLoader.GetTips();

            mode = TipMode.FullRotating;
            Scramble(new List<string>(tips.ToArray()));
            Initialize();
        }
开发者ID:summer-of-software,项目名称:vtank,代码行数:11,代码来源:GameTips.cs

示例15: GetActions

 public string[] GetActions()
 {
     Queue<string> actionNames = new Queue<string>();
     foreach (Action action in actions) {
         actionNames.Enqueue(action.getName);
     }
     return actionNames.ToArray();
 }
开发者ID:sentonnes,项目名称:RTS-Framework,代码行数:8,代码来源:WorldObject.cs


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