循环删除Dictionary集合中为空的Key,其他集合均可改造
程序员文章站
2022-06-19 17:26:29
/// /// 移除为空的Key/// /// /// private static Dictionary RemoveNullKey(Di ......
/// <summary>
/// 移除为空的key
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
private static dictionary<string, string> removenullkey(dictionary<string, string> dic)
{
string keynames = "";
foreach (string key in dic.keys)
{
if(string.isnullorempty(dic[key]))
{
keynames += key + ",";
}
}
string[] str_keynames = keynames.split(new char[] { ',' }, stringsplitoptions.removeemptyentries);
foreach (string key in str_keynames)
{
dic.remove(key);
}
return dic;
}