您的位置:首页 > 产品设计 > UI/UE

根据索引获取Dictionary的key和value值

2015-12-12 11:43 525 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace DictionaryHelper

{

public class DictionaryHelper<K,V>

{

public static K getKey(Dictionary<K, V> dict, int index)

{

K k=default(K);

int sum = 0;

foreach (K key in dict.Keys)

{

sum++;

if (sum == (index+1))

return key;

}

return k;

}

public static V getValue(Dictionary<K, V> dict, int index)

{

V v = default(V);

int sum = 0;

foreach (V value in dict.Values)

{

sum++;

if (sum == (index+1))

return value;

}

return v;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: