Dictionary<TKey, TValue> 进行where的枚举遍历

 Dictionary<int, string>进行枚举遍历的时候,使用IEnumerable<KeyValuePair<TKey, TValue>>.当然完全可以用foreach遍历,foreach把枚举的复杂性降低了。

 public static Dictionary<int, string> listPartition;
 IEnumerable<KeyValuePair<int, string>> partitiontemp = listPartition.Where(c => (!string.IsNullOrEmpty(province) ? c.Value.Trim().Contains(province) : true || !string.IsNullOrEmpty(ownCity) ? c.Value.Trim().Contains(ownCity) : true));
            if (partitiontemp!=null)
            {
                partition = partitiontemp.First().Key;
            }

[SerializableAttribute]
[ComVisibleAttribute(false)]
public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, 
ICollection<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, 
IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, 
IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, ISerializable, 
IDeserializationCallback

 

posted @ 2013-01-08 16:41  VORO  阅读(3211)  评论(0编辑  收藏  举报