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


C# HybridDictionary.Remove方法代码示例

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


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

示例1: All

		public void All ()
		{
			HybridDictionary dict = new HybridDictionary (true);
			dict.Add ("CCC", "ccc");
			dict.Add ("BBB", "bbb");
			dict.Add ("fff", "fff");
			dict ["EEE"] = "eee";
			dict ["ddd"] = "ddd";
			
			Assert.AreEqual (5, dict.Count, "#1");
			Assert.AreEqual ("eee", dict["eee"], "#2");
			
			dict.Add ("CCC2", "ccc");
			dict.Add ("BBB2", "bbb");
			dict.Add ("fff2", "fff");
			dict ["EEE2"] = "eee";
			dict ["ddd2"] = "ddd";
			dict ["xxx"] = "xxx";
			dict ["yyy"] = "yyy";

			Assert.AreEqual (12, dict.Count, "#3");
			Assert.AreEqual ("eee", dict["eee"], "#4");

			dict.Remove ("eee");
			Assert.AreEqual (11, dict.Count, "Removed/Count");
			Assert.IsFalse (dict.Contains ("eee"), "Removed/Contains(xxx)");
			DictionaryEntry[] entries = new DictionaryEntry [11];
			dict.CopyTo (entries, 0);

			Assert.IsTrue (dict.Contains ("xxx"), "Contains(xxx)");
			dict.Clear ();
			Assert.AreEqual (0, dict.Count, "Cleared/Count");
			Assert.IsFalse (dict.Contains ("xxx"), "Cleared/Contains(xxx)");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:34,代码来源:HybridDictionaryTest.cs

示例2: Test01


//.........这里部分代码省略.........
            {
                if (Array.IndexOf(arr, valuesLong[i]) < 0)
                {
                    Assert.False(true, string.Format("Error, Values doesn't contain {0} value", valuesLong[i], i));
                }
            }
            ind = Array.IndexOf(arr, intlStr);
            if (ind < 0)
            {
                Assert.False(true, string.Format("Error, Values doesn't contain {0} value", intlStr));
            }

            //
            //   [] Change long dictionary and check Values
            //

            hd.Clear();
            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            vs = hd.Values;
            if (vs.Count != len)
            {
                Assert.False(true, string.Format("Error, returned Values.Count = {0}", vs.Count));
            }

            hd.Remove(keysLong[0]);
            if (hd.Count != len - 1)
            {
                Assert.False(true, string.Format("Error, didn't remove element"));
            }
            if (vs.Count != len - 1)
            {
                Assert.False(true, string.Format("Error, Values were not updated after removal"));
            }
            arr = Array.CreateInstance(typeof(Object), hd.Count);
            vs.CopyTo(arr, 0);
            ind = Array.IndexOf(arr, valuesLong[0]);
            if (ind >= 0)
            {
                Assert.False(true, string.Format("Error, Values still contains removed value " + ind));
            }

            hd.Add(keysLong[0], "new item");
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, didn't add element"));
            }
            if (vs.Count != len)
            {
                Assert.False(true, string.Format("Error, Values were not updated after addition"));
            }
            arr = Array.CreateInstance(typeof(Object), hd.Count);
            vs.CopyTo(arr, 0);
            ind = Array.IndexOf(arr, "new item");
            if (ind < 0)
            {
                Assert.False(true, string.Format("Error, Values doesn't contain added value "));
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:67,代码来源:GetValuesTests.cs

示例3: Test01


//.........这里部分代码省略.........

            //
            //  Attempt to get Entry should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { de = en.Entry; });

            //=========================================================
            // --------------------------------------------------------
            //
            //   Modify dictionary when enumerating
            //
            //  [] Enumerator and short modified HD (list)
            //
            hd.Clear();
            if (hd.Count < 1)
            {
                for (int i = 0; i < valuesShort.Length; i++)
                {
                    hd.Add(keysShort[i], valuesShort[i]);
                }
            }

            en = hd.GetEnumerator();
            res = en.MoveNext();
            if (!res)
            {
                Assert.False(true, string.Format("Error, MoveNext returned false"));
            }
            curr = (DictionaryEntry)en.Current;
            de = en.Entry;
            k = en.Key;
            v = en.Value;
            int cnt = hd.Count;
            hd.Remove(keysShort[0]);
            if (hd.Count != cnt - 1)
            {
                Assert.False(true, string.Format("Error, didn't remove item with 0th key"));
            }

            // will return just removed item
            DictionaryEntry curr2 = (DictionaryEntry)en.Current;
            if (!curr.Equals(curr2))
            {
                Assert.False(true, string.Format("Error, current returned different value after modification"));
            }

            // will return just removed item
            DictionaryEntry de2 = en.Entry;
            if (!de.Equals(de2))
            {
                Assert.False(true, string.Format("Error, Entry returned different value after modification"));
            }

            // will return just removed item
            Object k2 = en.Key;
            if (!k.Equals(k2))
            {
                Assert.False(true, string.Format("Error, Key returned different value after modification"));
            }


            // will return just removed item
            Object v2 = en.Value;
            if (!v.Equals(v2))
            {
                Assert.False(true, string.Format("Error, Value returned different value after modification"));
开发者ID:er0dr1guez,项目名称:corefx,代码行数:67,代码来源:GetEnumeratorTests.cs

示例4: Test01


//.........这里部分代码省略.........
                Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", hd.Count, len));
            }
            for (int i = 0; i < len; i++)
            {
                if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i]) != 0)
                {
                    Assert.False(true, string.Format("Error, Item() returned unexpected value", i));
                }
                if (hd[keysLong[i].ToUpper()] != null)
                {
                    Assert.False(true, string.Format("Error, Item() returned non-null for uppercase key", i));
                }
            }

            //
            // [] Clear() for dictionary with multiple entries
            //
            hd.Clear();
            if (hd.Count != 0)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of 0 after Clear()", hd.Count));
            }

            //
            // [] few elements not overriding Equals()
            //
            hd.Clear();
            Hashtable[] lbls = new Hashtable[2];
            ArrayList[] bs = new ArrayList[2];
            lbls[0] = new Hashtable();
            lbls[1] = new Hashtable();
            bs[0] = new ArrayList();
            bs[1] = new ArrayList();
            hd.Add(lbls[0], bs[0]);
            hd.Add(lbls[1], bs[1]);
            if (hd.Count != 2)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of 2", hd.Count));
            }
            if (!hd.Contains(lbls[0]))
            {
                Assert.False(true, string.Format("Error, doesn't contain 1st special item"));
            }
            if (!hd.Contains(lbls[1]))
            {
                Assert.False(true, string.Format("Error, doesn't contain 2nd special item"));
            }
            if (hd.Values.Count != 2)
            {
                Assert.False(true, string.Format("Error, Values.Count returned {0} instead of 2", hd.Values.Count));
            }

            hd.Remove(lbls[1]);
            if (hd.Count != 1)
            {
                Assert.False(true, string.Format("Error, failed to remove item"));
            }
            if (hd.Contains(lbls[1]))
            {
                Assert.False(true, string.Format("Error, failed to remove special item"));
            }

            //
            // [] many elements not overriding Equals()
            //
            hd.Clear();
            lbls = new Hashtable[BIG_LENGTH];
            bs = new ArrayList[BIG_LENGTH];
            for (int i = 0; i < BIG_LENGTH; i++)
            {
                lbls[i] = new Hashtable();
                bs[i] = new ArrayList();
                hd.Add(lbls[i], bs[i]);
            }
            if (hd.Count != BIG_LENGTH)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", hd.Count, BIG_LENGTH));
            }
            for (int i = 0; i < BIG_LENGTH; i++)
            {
                if (!hd.Contains(lbls[0]))
                {
                    Assert.False(true, string.Format("Error, doesn't contain 1st special item"));
                }
            }
            if (hd.Values.Count != BIG_LENGTH)
            {
                Assert.False(true, string.Format("Error, Values.Count returned {0} instead of {1}", hd.Values.Count, BIG_LENGTH));
            }

            hd.Remove(lbls[0]);
            if (hd.Count != BIG_LENGTH - 1)
            {
                Assert.False(true, string.Format("Error, failed to remove item"));
            }
            if (hd.Contains(lbls[0]))
            {
                Assert.False(true, string.Format("Error, failed to remove special item"));
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:CtorTests.cs

示例5: Test01

        public void Test01()
        {
            IntlStrings intl;
            HybridDictionary hd;

            const int BIG_LENGTH = 100;

            // simple string values
            string[] valuesShort =
            {
                "",
                " ",
                "$%^#",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keysShort =
            {
                Int32.MaxValue.ToString(),
                " ",
                System.DateTime.Today.ToString(),
                "",
                "$%^#"
            };

            string[] valuesLong = new string[BIG_LENGTH];
            string[] keysLong = new string[BIG_LENGTH];

            int cnt = 0;            // Count

            // initialize IntStrings
            intl = new IntlStrings();

            for (int i = 0; i < BIG_LENGTH; i++)
            {
                valuesLong[i] = "Item" + i;
                keysLong[i] = "keY" + i;
            }

            // [] HybridDictionary is constructed as expected
            //-----------------------------------------------------------------

            hd = new HybridDictionary();

            // [] Remove() on empty dictionary
            //
            cnt = hd.Count;
            try
            {
                hd.Remove(null);
                Assert.False(true, string.Format("Error, no exception"));
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception e)
            {
                Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString()));
            }

            cnt = hd.Count;
            hd.Remove("some_string");
            if (hd.Count != cnt)
            {
                Assert.False(true, string.Format("Error, changed dictionary after Remove(some_string)"));
            }

            cnt = hd.Count;
            hd.Remove(new Hashtable());
            if (hd.Count != cnt)
            {
                Assert.False(true, string.Format("Error, changed dictionary after Remove(some_string)"));
            }

            //
            // [] Remove() on short dictionary with simple strings
            //

            cnt = hd.Count;
            int len = valuesShort.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length));
            }
            //

            for (int i = 0; i < len; i++)
            {
                cnt = hd.Count;
                hd.Remove(keysShort[i]);
                if (hd.Count != cnt - 1)
                {
                    Assert.False(true, string.Format("Error, failed to remove item", i));
                }
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:RemoveObjTests.cs

示例6: GetNamespacesInScope

        // Get all namespaces in the local or scope from the last parent
        private  IDictionary GetNamespacesInScope(NamespaceScope scope)
        {
            int i = 0;

            switch (scope)
            {
                case NamespaceScope.All:
                    i = 0;
                    break;

                case NamespaceScope.Local:
                    i = _lastDecl;
                    int lastScopeCount = _nsDeclarations[i].ScopeCount;
                    while (_nsDeclarations[i].ScopeCount == lastScopeCount)  
                        i--;
                    i++;
                    break;
            }

            HybridDictionary dict = new HybridDictionary(_lastDecl -i + 1);

            for (; i < _lastDecl; i++)
            {
                string prefix = _nsDeclarations[i].Prefix;
                string xmlNamespace    = _nsDeclarations[i].Uri;

                Debug.Assert(prefix != null);
                if (xmlNamespace.Length > 0 || prefix.Length > 0)
                {
                    dict[prefix] = xmlNamespace;
                }
                else
                {
                    // default namespace redeclared to "" -> remove from list
                    dict.Remove(prefix);
                }
            }

            return dict;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:41,代码来源:XmlnsDictionary.cs

示例7: Test01


//.........这里部分代码省略.........
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of 0 after Clear()", hd.Count));
            }

            //
            // [] few elements not overriding Equals()
            //
            hd.Clear();
            Hashtable[] lbls = new Hashtable[2];
            ArrayList[] bs = new ArrayList[2];
            lbls[0] = new Hashtable();
            lbls[1] = new Hashtable();
            bs[0] = new ArrayList();
            bs[1] = new ArrayList();
            hd.Add(lbls[0], bs[0]);
            hd.Add(lbls[1], bs[1]);
            if (hd.Count != 2)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of 2", hd.Count));
            }
            if (!hd.Contains(lbls[0]))
            {
                Assert.False(true, string.Format("Error, doesn't contain 1st special item"));
            }
            if (!hd.Contains(lbls[1]))
            {
                Assert.False(true, string.Format("Error, doesn't contain 2nd special item"));
            }
            if (hd.Values.Count != 2)
            {
                Assert.False(true, string.Format("Error, Values.Count returned {0} instead of 2", hd.Values.Count));
            }

            hd.Remove(lbls[1]);
            if (hd.Count != 1)
            {
                Assert.False(true, string.Format("Error, failed to remove item"));
            }
            if (hd.Contains(lbls[1]))
            {
                Assert.False(true, string.Format("Error, failed to remove special item"));
            }

            //
            // [] many elements not overriding Equals()
            //
            hd.Clear();
            lbls = new Hashtable[BIG_LENGTH];
            bs = new ArrayList[BIG_LENGTH];
            for (int i = 0; i < BIG_LENGTH; i++)
            {
                lbls[i] = new Hashtable();
                bs[i] = new ArrayList();
                hd.Add(lbls[i], bs[i]);
            }
            if (hd.Count != BIG_LENGTH)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", hd.Count, BIG_LENGTH));
            }
            for (int i = 0; i < BIG_LENGTH; i++)
            {
                if (!hd.Contains(lbls[0]))
                {
                    Assert.False(true, string.Format("Error, doesn't contain 1st special item"));
                }
            }
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:CtorIntBoolTests.cs

示例8: ReleaseInstanceDataForTriggerBinding

        private static void ReleaseInstanceDataForTriggerBinding(
            BindingBase                                 binding,
            HybridDictionary                            instanceValues,
            EventHandler<BindingValueChangedEventArgs>  handler)
        {
            BindingExpressionBase bindingExpr = (BindingExpressionBase)instanceValues[binding];

            if (bindingExpr != null)
            {
                bindingExpr.ValueChanged -= handler;
                bindingExpr.Detach();
                instanceValues.Remove(binding);
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:14,代码来源:StyleHelper.cs

示例9: ProcessInstanceValue

        //
        //  This method
        //  1. Adds or removes per-instance state on the container/child (push model)
        //  2. Processes a single value that needs per-instance storage
        //
        internal static void ProcessInstanceValue(
            DependencyObject    target,
            int                 childIndex,
            HybridDictionary    instanceValues,
            DependencyProperty  dp,
            int                 i,
            bool                apply)
        {
            // If we get this far, it's because there's a value
            // in the property value list of an active style that requires
            // per-instance storage.  The initialization (CreateInstaceData)
            // should have created the InstanceValues hashtable by now.
            Debug.Assert(instanceValues != null, "InstanceValues hashtable should have been created at initialization time.");

            InstanceValueKey key = new InstanceValueKey(childIndex, dp.GlobalIndex, i);

            if (apply)
            {
                // Store a sentinel value in per-instance StyleData.
                // The actual value is created only on demand.
                instanceValues[key] = NotYetApplied;
            }
            else
            {
                // Remove the instance value from the table
                object value = instanceValues[key];
                instanceValues.Remove(key);

                Expression expr;
                Freezable freezable;

                if ((expr = value as Expression)!= null)
                {
                    // if the instance value is an expression, detach it
                    expr.OnDetach(target, dp);
                }
                else if ((freezable = value as Freezable)!= null)
                {
                    // if the instance value is a Freezable, remove its
                    // inheritance context
                    target.RemoveSelfAsInheritanceContext(freezable, dp);
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:49,代码来源:StyleHelper.cs

示例10: AllTopicsForNewsletter

    // Updated 2004-01-29 by CraigAndera
    public IEnumerable AllTopicsForNewsletter(AbsoluteTopicName newsletter)
    {
      // HybridDictionary switches between using a ListDictionary and a Hashtable 
      // depending on the size of the collection - should be a good choice since we don't
      // know how big the collection of topic names will be 
      HybridDictionary answer = new HybridDictionary(); 

      ContentBase cb = ContentBaseForNewsletter(newsletter);

      foreach (string s in TheFederation.GetTopicListPropertyValue(newsletter, "Topics"))
      {
        // If the wildcard appears, ignore all the other topics listed - include every topic
        if (s == "*")
        {
          answer.Clear(); 
          foreach (AbsoluteTopicName atn in cb.AllTopics(false))
          {
            answer.Add(atn.Fullname, atn); 
          }
          // No need to continue iterating after we find the wildcard 
          break; 
        }
        else
        {
          RelativeTopicName rel = new RelativeTopicName(s);
          foreach (AbsoluteTopicName atn in cb.AllAbsoluteTopicNamesThatExist(rel))
          {
            answer.Add(atn.Fullname, atn); 
          }
        }
      }

      // Now we need to remove any topics that appear in the Exclude field
      foreach (string s in TheFederation.GetTopicListPropertyValue(newsletter, "Exclude"))
      {
        RelativeTopicName rel = new RelativeTopicName(s);
        foreach (AbsoluteTopicName atn in cb.AllAbsoluteTopicNamesThatExist(rel))
        {
          answer.Remove(atn.Fullname); 
        }
      }

      // Do the same for "Excludes", since it's hard to remember which one to use
      foreach (string s in TheFederation.GetTopicListPropertyValue(newsletter, "Excludes"))
      {
        RelativeTopicName rel = new RelativeTopicName(s);
        foreach (AbsoluteTopicName atn in cb.AllAbsoluteTopicNamesThatExist(rel))
        {
          answer.Remove(atn.Fullname); 
        }
      }

      return answer.Values;
    }
开发者ID:nuxleus,项目名称:flexwiki,代码行数:55,代码来源:NewsletterManager.cs

示例11: HybridDictionary

 void IToolboxService.ResetToolbox()
 {
     IMxUIService service = (IMxUIService) this._serviceProvider.GetService(typeof(IMxUIService));
     if (service.ShowMessage("All toolbox customizations in all sections will be lost.\r\nAre you sure you want to continue?", "Reset Toolbox", MessageBoxIcon.Exclamation, MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
     {
         IToolboxService service2 = this;
         ICollection is2 = this.ReadToolboxFromConfig();
         IDictionary dictionary = new HybridDictionary(true);
         foreach (ToolboxSection section in this._sections)
         {
             dictionary[section.Name] = section;
         }
         foreach (ToolboxSection section2 in is2)
         {
             ToolboxSection section3 = (ToolboxSection) dictionary[section2.Name];
             if (section3 != null)
             {
                 section3.ClearToolboxDataItems();
                 foreach (ToolboxDataItem item in section2.ToolboxDataItems)
                 {
                     section3.AddToolboxDataItem(item, false);
                 }
                 section3.FireItemsChanged();
                 dictionary.Remove(section2.Name);
                 continue;
             }
             service2.AddToolboxSection(section2);
         }
         bool flag = false;
         foreach (ToolboxSection section4 in dictionary.Values)
         {
             if (section4 == service2.ActiveSection)
             {
                 flag = true;
             }
             service2.RemoveToolboxSection(section4);
         }
         if (flag)
         {
             if (this._sections.Count > 0)
             {
                 service2.ActiveSection = (ToolboxSection) this._sections[0];
             }
             else
             {
                 service2.ActiveSection = null;
             }
         }
     }
 }
开发者ID:ikvm,项目名称:webmatrix,代码行数:50,代码来源:ToolboxService.cs

示例12: GetCollectionDelta

 private ICollection GetCollectionDelta(ICollection original, ICollection modified)
 {
     if (((original != null) && (modified != null)) && (original.Count != 0))
     {
         IEnumerator enumerator = modified.GetEnumerator();
         if (enumerator != null)
         {
             IDictionary dictionary = new HybridDictionary();
             foreach (object obj2 in original)
             {
                 if (dictionary.Contains(obj2))
                 {
                     int num = (int) dictionary[obj2];
                     dictionary[obj2] = ++num;
                 }
                 else
                 {
                     dictionary.Add(obj2, 1);
                 }
             }
             ArrayList list = null;
             for (int i = 0; (i < modified.Count) && enumerator.MoveNext(); i++)
             {
                 object current = enumerator.Current;
                 if (dictionary.Contains(current))
                 {
                     if (list == null)
                     {
                         list = new ArrayList();
                         enumerator.Reset();
                         for (int j = 0; (j < i) && enumerator.MoveNext(); j++)
                         {
                             list.Add(enumerator.Current);
                         }
                         enumerator.MoveNext();
                     }
                     int num4 = (int) dictionary[current];
                     if (--num4 == 0)
                     {
                         dictionary.Remove(current);
                     }
                     else
                     {
                         dictionary[current] = num4;
                     }
                 }
                 else if (list != null)
                 {
                     list.Add(current);
                 }
             }
             if (list != null)
             {
                 return list;
             }
         }
     }
     return modified;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:59,代码来源:CollectionCodeDomSerializer.cs


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