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


C# OrderedDictionary.Clear方法代码示例

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


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

示例1: Common

		private void Common (OrderedDictionary od)
		{
			Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
			Assert.AreEqual (0, od.Count, "Count-0");
			Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
			od.Add ("a", "1");
			Assert.AreEqual (1, od.Count, "Count-1");
			od["a"] = "11";
			Assert.AreEqual ("11", od["a"], "this[string]");
			od[0] = "111";
			Assert.AreEqual ("111", od[0], "this[int]");

			DictionaryEntry[] array = new DictionaryEntry[2];
			od.CopyTo (array, 1);

			Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
			Assert.AreEqual (1, od.Keys.Count, "Keys");
			Assert.AreEqual (1, od.Values.Count, "Values");
			Assert.IsTrue (od.Contains ("a"), "Contains(a)");
			Assert.IsFalse (od.Contains ("111"), "Contains(111)");

			od.Insert (0, "b", "2");
			Assert.AreEqual (2, od.Count, "Count-2");
			od.Add ("c", "3");
			Assert.AreEqual (3, od.Count, "Count-3");

			OrderedDictionary ro = od.AsReadOnly ();

			od.RemoveAt (2);
			Assert.AreEqual (2, od.Count, "Count-4");
			Assert.IsFalse (od.Contains ("c"), "Contains(c)");

			od.Remove ("b");
			Assert.AreEqual (1, od.Count, "Count-5");
			Assert.IsFalse (od.Contains ("b"), "Contains(b)");

			od.Clear ();
			Assert.AreEqual (0, od.Count, "Count-6");

			Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
			// it's a read-only reference
			Assert.AreEqual (0, od.Count, "Count-7");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:43,代码来源:OrderedDictionaryTest.cs

示例2: ClearTests

 public void ClearTests()
 {
     var d = new OrderedDictionary();
     d.Clear();
     Assert.Equal(0, d.Count);
     for (int i = 0; i < 1000; i++)
     {
         d.Add(i, i);
     }
     d.Clear();
     Assert.Equal(0, d.Count);
     d.Clear();
     Assert.Equal(0, d.Count);
     for (int i = 0; i < 1000; i++)
     {
         d.Add("foo", "bar");
         d.Clear();
         Assert.Equal(0, d.Count);
     }
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:20,代码来源:OrderedDictionaryTests.cs

示例3: ReadOnly_Clear

		public void ReadOnly_Clear ()
		{
			OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
			od.Clear ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:5,代码来源:OrderedDictionaryTest.cs

示例4: FillData

        void FillData()
        {
            DateTime theMonthToFilter = DateTime.Today;

            if (calendar1.DisplayDate != null)
            {
                theMonthToFilter = (DateTime)calendar1.DisplayDate;
            }

            var startOfMonth = new DateTime(theMonthToFilter.Year, theMonthToFilter.Month, 1);
            var endOfMonth = new DateTime(theMonthToFilter.Year, theMonthToFilter.Month, 1).AddMonths(1).AddDays(-1).AddHours(23).AddMinutes(59); ;

            //calendar1.SelectedDate;
                DataRowView dr = ((DataRowView)dataGrid_projects.SelectedItem);

            if (dr==null) return;

                String SQL = "SELECT * FROM times WHERE project_id = '" + dr.Row[0] + "' AND julianday(start_date) >= julianday('" + DateTimeSQLite(startOfMonth) + "') AND julianday(end_date) <= julianday('" + DateTimeSQLite(endOfMonth) + "')";
                DataSet ds = new DataSet();
                using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(SQL, cnn))
                {
                    dataAdapter.Fill(ds);
                }

                DataView dv = ds.Tables[0].DefaultView;

                DataTable dt = new DataTable();
                dt.Columns.Add(new DataColumn("Link", typeof(DataRow)));
                dt.Columns.Add(new DataColumn("Readable", typeof(string)));
                dt.Columns.Add(new DataColumn("Day", typeof(int)));
                dt.Columns.Add(new DataColumn("Times", typeof(string)));
                dt.Columns.Add(new DataColumn("Duration", typeof(string)));
                dt.Columns.Add(new DataColumn("Description", typeof(string)));

               // dt.Columns[0].Visible = false;

                OrderedDictionary dtIndex = new OrderedDictionary();
                dtIndex.Clear();

                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    dtIndex.Add(ds.Tables[0].Columns[i].ColumnName, i);
                }

                TimeSpan total = new TimeSpan();
                foreach (DataRow r in ds.Tables[0].Rows)
                {

                    var id = r[(int)dtIndex["id"]];
                    var project_id = r[(int)dtIndex["project_id"]];
                    DateTime start_date = (DateTime)r[(int)dtIndex["start_date"]];
                    DateTime end_date =(DateTime)r[(int)dtIndex["end_date"]];
                    var desc = r[(int)dtIndex["description"]];

                    TimeSpan diff = end_date-start_date;
                    total = total + diff;

                    String diffTime = diff.Hours.ToString() + " Hrs " + diff.Minutes.ToString() + "Mins";
                    String readable = Ordinal(Convert.ToInt32(start_date.ToString("dd"))) + " " + start_date.ToString("dddd");

                    dt.Rows.Add(r,readable,start_date.ToString("dd"), start_date.ToString("h:mm tt") + " - " + end_date.ToString("h:mm tt"), diffTime, desc);
                }

                HrsLabel.Content = (total.Days * 24 + total.Hours) + "hrs " + total.Minutes + " mins = " + (total.TotalHours) + " hrs";

                DataView dvdt = dt.DefaultView;
                dvdt.Sort = "Day ASC";

                ICollectionView iG = CollectionViewSource.GetDefaultView(dvdt);
                iG.GroupDescriptions.Add(new PropertyGroupDescription("Day"));
                dataGrid.ItemsSource = iG;
        }
开发者ID:Replica-,项目名称:Consultant,代码行数:72,代码来源:MainWindow.xaml.cs

示例5: AsReadOnly_AttemptingToModifyDictionary_Throws

        public void AsReadOnly_AttemptingToModifyDictionary_Throws()
        {
            OrderedDictionary orderedDictionary = new OrderedDictionary().AsReadOnly();
            Assert.Throws<NotSupportedException>(() => orderedDictionary[0] = "value");
            Assert.Throws<NotSupportedException>(() => orderedDictionary["key"] = "value");
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Add("key", "value"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Insert(0, "key", "value"));
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Remove("key"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.RemoveAt(0));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Clear());
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:OrderedDictionaryTests.cs

示例6: processSales

        protected void processSales()
        {
            OrderedDictionary soldBoughtItems = new OrderedDictionary();

            /*
             * First of all the old system was not possible to do with SQL
             * Would of required to do a SQL Query for each itemId sold and bought by all players
             * That would of ment over 10,000 items x 2 (buyers+sellers) so 20,000 queries to process.
             * 
             * The new system I created to fix this.
             * Works like this it everytime this runs matches up 1 GE Buying/Selling auction.
             * Then loops it 100 times or until no more matches are possible.
             * 
             * TODO: Match Buyer's of larger item quantity with Sellers with larger quanity instead of Sellers with
             * any item quantity. (this requires editing the query below to a better suited query).
             */

            BuyOffer buyer = null;
            SellOffer seller = null;
            int itemId;
            int itemAmount;
            int price;
            int sold;
            int bought;
            int collectedItem;
            int collectedGold;
            int overpaid;
            byte slot;
            long playerHash;

            SQLiteDatabase db = new SQLiteDatabase(Constants.databaseName);
            for (int processNumSales = 0; processNumSales < 100; processNumSales++)
            {
                soldBoughtItems.Clear();

                //Can't do more then 1 sale at a time, LIMIT 100 wont work since it will pick duplicate sellers.
                DataTable dt = db.ExecuteQuery("SELECT S.itemId AS sell_itemId, S.amount AS sell_amount, S.price AS sell_price, S.sold AS sell_sold, S.collectedItem AS sell_collectedItem, S.collectedGold AS sell_collectedGold, S.overpaid AS sell_overpaid, S.slot AS sell_slot, S.playerHash AS sell_playerHash, B.itemId AS buy_itemId, B.amount AS buy_amount, B.price AS buy_price, B.bought AS buy_bought, B.collectedItem AS buy_collectedItem, B.collectedGold AS buy_collectedGold, B.overpaid AS buy_overpaid, B.slot AS buy_slot, B.playerHash AS buy_playerHash FROM grandExchangeBuying AS B, grandExchangeSelling AS S ON B.itemId = S.itemId AND B.aborted = 0 AND S.aborted = 0 AND B.price >= S.price AND S.sold < S.amount AND B.bought < B.amount ORDER BY B.price DESC LIMIT 1");

                if (dt.Rows.Count == 0)
                {
                    db.CloseDatabase();
                    return;
                }
                else
                {
                    itemId = Convert.ToInt32(dt.Rows[0]["sell_itemId"]);
                    itemAmount = Convert.ToInt32(dt.Rows[0]["sell_amount"]);
                    price = Convert.ToInt32(dt.Rows[0]["sell_price"]);
                    sold = Convert.ToInt32(dt.Rows[0]["sell_sold"]);
                    collectedItem = Convert.ToInt32(dt.Rows[0]["sell_collectedItem"]);
                    collectedGold = Convert.ToInt32(dt.Rows[0]["sell_collectedGold"]);
                    overpaid = Convert.ToInt32(dt.Rows[0]["sell_overpaid"]);
                    slot = Convert.ToByte(dt.Rows[0]["sell_slot"]);
                    playerHash = (long)dt.Rows[0]["sell_playerHash"];

                    seller = new SellOffer(itemId, itemAmount, price, sold, collectedItem, collectedGold, overpaid, slot, playerHash);

                    itemId = Convert.ToInt32(dt.Rows[0]["buy_itemId"]);
                    itemAmount = Convert.ToInt32(dt.Rows[0]["buy_amount"]);
                    price = Convert.ToInt32(dt.Rows[0]["buy_price"]);
                    bought = Convert.ToInt32(dt.Rows[0]["buy_bought"]);
                    collectedItem = Convert.ToInt32(dt.Rows[0]["buy_collectedItem"]);
                    collectedGold = Convert.ToInt32(dt.Rows[0]["buy_collectedGold"]);
                    overpaid = Convert.ToInt32(dt.Rows[0]["buy_overpaid"]);
                    slot = Convert.ToByte(dt.Rows[0]["buy_slot"]);
                    playerHash = (long)dt.Rows[0]["buy_playerHash"];

                    buyer = new BuyOffer(itemId, itemAmount, price, bought, collectedItem, collectedGold, overpaid, slot, playerHash);
                }

                if (seller == null || buyer == null) continue;

                int amountToBuy = buyer.getTotalAmount() - buyer.getAmountTraded();
                int amountToSell = seller.getTotalAmount() - seller.getAmountTraded();

                // This check will never happen. SQL Query will not allow it.. Just old code I left in.
                if (amountToBuy <= 0 || amountToSell <= 0)
                    continue;

                int amount = (amountToBuy > amountToSell) ? amountToSell : amountToBuy;
                // Buys from Seller a random amount of a item.
                amount = misc.random(1, amount);

                // Buyer will pay minimum what the seller wants.
                int amountBuyerOverpaid = (buyer.getPriceEach() - seller.getPriceEach()) * amount; // buyer is paying more than the seller wants, therefore MAY recieve this amount as a refund.
                bool buyerKeepsRefund = misc.random(1) == 0; // if 0, the buyer gets a refund, if its 1...the seller gets more.
                buyer.setAmountTraded(buyer.getAmountTraded() + amount);
                seller.setAmountTraded(seller.getAmountTraded() + amount);

                /**
                    * How much refunded gold Buyer gets in addition to his previous refunded gold.
                    * or
                    * How much of the Buyer's overpaid gold that they couldn't keep goes as extra profit to the Seller.
                    */
                if (buyerKeepsRefund && amountBuyerOverpaid > 0)
                    buyer.setAmountOverpaid(buyer.getAmountOverpaid() + amountBuyerOverpaid);
                else if (!buyerKeepsRefund && amountBuyerOverpaid > 0)
                    seller.setAmountOverpaid(seller.getAmountOverpaid() + amountBuyerOverpaid);

                // Shows amount of Item Buyer bought in Slot 1 minus how much he already took out.
//.........这里部分代码省略.........
开发者ID:slapglif,项目名称:runescape-server-csharp,代码行数:101,代码来源:GrandExchange.cs


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