新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
淺談C#中的Stack和Queue對象
C# Stack對象和C# Queue對象

柴桑網(wǎng)站建設公司創(chuàng)新互聯(lián)公司,柴桑網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為柴桑成百上千家提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設要多少錢,請找那個售后服務好的柴桑做網(wǎng)站的公司定做!
您希望通過將所有C# Stack對象和C# Queue對象替換為相應的泛型版本以提高應用程序的效率,并使得代碼更易于使用。當結(jié)構(gòu)體或其他值類型存儲在這些數(shù)據(jù)結(jié)構(gòu)中時,會導致裝箱/拆箱操作,這時就需要這么做。
C#解決方案
使用System.Collections.Generic.Stack和System.Collections.Generic.Queue對象來替換現(xiàn)有的System.Collections.Stack和System.Collections.Queue對象。
這里有一個簡單地使用System.Collections.Queue對象的簡單例子:
- publicstaticvoidUseNonGenericQueue()
- {
- //創(chuàng)建一個非泛型隊列對象
- QueuenumericQueue=newQueue();
- //進隊(導致裝箱操作).
- numericQueue.Enqueue(1);
- numericQueue.Enqueue(2);
- numericQueue.Enqueue(3);
- //出隊并顯示項(導致拆箱操作)
- Console.WriteLine(numericQueue.Dequeue());
- Console.WriteLine(numericQueue.Dequeue());
- Console.WriteLine(numericQueue.Dequeue().ToString());
- }
以上介紹C# Stack對象和C# Queue對象
網(wǎng)站欄目:淺談C#中的Stack和Queue對象
網(wǎng)頁地址:http://m.fisionsoft.com.cn/article/cdeejpi.html


咨詢
建站咨詢
