System.Collections.Hashtable.ContainsValue C# (CSharp) Method

ContainsValue() public method

public ContainsValue ( Object value ) : bool
value Object
return bool
        public virtual bool ContainsValue(Object value)
        {
            if (value == null)
            {
                for (int i = _buckets.Length; --i >= 0;)
                {
                    if (_buckets[i].key != null && _buckets[i].key != _buckets && _buckets[i].val == null)
                        return true;
                }
            }
            else
            {
                for (int i = _buckets.Length; --i >= 0;)
                {
                    Object val = _buckets[i].val;
                    if (val != null && val.Equals(value)) return true;
                }
            }
            return false;
        }

Usage Example

Esempio n. 1
0
        public void TestCtorDictionarySingle()
        {
            // No exception
            var hash = new Hashtable(new Hashtable(), 1f);
            // No exception
            hash = new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable()), 1f), 1f), 1f), 1f);

            // []test to see if elements really get copied from old dictionary to new hashtable
            Hashtable tempHash = new Hashtable();
            // this for assumes that MinValue is a negative!
            for (long i = long.MinValue; i < long.MinValue + 100; i++)
            {
                tempHash.Add(i, i);
            }

            hash = new Hashtable(tempHash, 1f);

            // make sure that new hashtable has the elements in it that old hashtable had
            for (long i = long.MinValue; i < long.MinValue + 100; i++)
            {
                Assert.True(hash.ContainsKey(i));
                Assert.True(hash.ContainsValue(i));
            }

            //[]make sure that there are no connections with the old and the new hashtable
            tempHash.Clear();
            for (long i = long.MinValue; i < long.MinValue + 100; i++)
            {
                Assert.True(hash.ContainsKey(i));
                Assert.True(hash.ContainsValue(i));
            }
        }
All Usage Examples Of System.Collections.Hashtable::ContainsValue