示例#1
0
 /// <summary>
 /// Gets the collection of values associated with the specified key, or an empty collection
 /// if no such items exist. Returns true iff any items are associated with the key.
 /// </summary>
 public bool TryGetValue(string key, out ValuesCollection <TValue> value)
 {
     if (_items.ContainsKey(key) && _items[key].Count > 0)
     {
         value = new ValuesCollection <TValue>(_items[key], _isReadOnly);
         return(true);
     }
     else
     {
         value = default(ValuesCollection <TValue>);
         return(false);
     }
 }
示例#2
0
 /// <summary>
 /// Adds all items from the specified value collection, associating them with
 /// the specified key. Throws an exception if the specified key already has items
 /// associated with it.
 /// </summary>
 /// <param name="key">Key to associate the items with.</param>
 /// <param name="value">Collection containing the values to add.</param>
 public void Add(string key, ValuesCollection <TValue> value)
 {
     if (_isReadOnly)
     {
         throwNonWritable();
     }
     if (_items.ContainsKey(key) && _items[key].Count == 0)
     {
         _items[key].AddRange(value);
     }
     else
     {
         _items.Add(key, new List <TValue>(value));
     }
 }