System.Collections.SortedList.ContainsKey C# (CSharp) Method

ContainsKey() public method

public ContainsKey ( Object key ) : bool
key Object
return bool
        public virtual bool ContainsKey(Object key)
        {
            // Yes, this is a SPEC'ed duplicate of Contains().
            return IndexOfKey(key) >= 0;
        }

Same methods

SortedList::ContainsKey ( object key ) : bool

Usage Example

Example #1
1
        private static Match[] MatchSubstring(string i_source, string i_matchPattern, bool i_uniqueMatch)
        {
            //<note> use RegexOptions.Multiline, otherwise it will treat the whole thing as 1 string
            Regex regex = new Regex(i_matchPattern, RegexOptions.Multiline);

            MatchCollection matchCollection = regex.Matches(i_source);

            Match[] result;
            if (!i_uniqueMatch)
            {
                result = new Match[matchCollection.Count];
                matchCollection.CopyTo(result, 0);
            }
            else
            {
                //<note> cannot use HashSet<Match> because each Match object is unique, even though they may have same value (string). Can use HashSet<string>
                //SortedList is more like sorted Dictionary<key, value>
                SortedList uniqueMatchCollection = new SortedList();
                foreach(Match match in matchCollection)
                {
                    if (!uniqueMatchCollection.ContainsKey(match.Value))
                    {
                        uniqueMatchCollection.Add(match.Value, match);
                    }
                }

                result = new Match[uniqueMatchCollection.Count];
                uniqueMatchCollection.Values.CopyTo(result, 0);     //<note> cannot use uniqueMatchCollection.CopyTo(...) since SortedList member is not type-match with destination array member
            }

            Console.WriteLine("Found {0} matches", result.Length);
            return result;
        }
All Usage Examples Of System.Collections.SortedList::ContainsKey