多个Dictionary<string, object>合并到一个Dictionary<string, object>?
staticvoidMain(string[]args) { &n...
static void Main(string[] args) { Dictionary<string, object> htmlAttributes = new Dictionary<string, object>(); //Dictionary<string, object> htmlAttributes1 = GetHtmlAttributes(); //foreach (KeyValuePair<string, object> k in GetHtmlAttributes()) //{ // htmlAttributes.Add(k.Key, k.Value); //} htmlAttributes.Concat(GetHtmlAttributes()); Console.WriteLine(); } private static Dictionary<string, object> GetHtmlAttributes() { Dictionary<string, object> htmlAttributes = new Dictionary<string, object>(); htmlAttributes["required"] = "true"; htmlAttributes["maxlength"] = "max.MaximumLength"; htmlAttributes["minlength"] = "min.MinimumLength"; htmlAttributes["rangemin"] = "range.Minimum"; htmlAttributes["rangemax"] = "range.Maximum"; htmlAttributes["regexp"] = "regexp.Pattern"; return htmlAttributes; }htmlAttributes.Count() = 0 ? 谁能帮我解决这个问题么 ?
展开
展开全部
var dicTest1=new Dictionary<string.Object>
{
{"test1","str1"},
{"test2",100}
};
var dicTest2=new Dictionary<string.Object>
{
{"test1","str1"},
{"test3","str3"},
{"test4", true},
{"test5",new DateTime()}
};
var dicTest3=dicTest1.Union(test2);
foreach(var keyValuePair in dicTest3)
{
Console.WriteLine("{0}:{1}",keyValuePair.Key,keyValuePair.Value);
}
Console.ReadLine();
注意要using System.Linq 的nameSpace
另外如果不想去重的话 就用
dicTest1.Concat(test2);
{
{"test1","str1"},
{"test2",100}
};
var dicTest2=new Dictionary<string.Object>
{
{"test1","str1"},
{"test3","str3"},
{"test4", true},
{"test5",new DateTime()}
};
var dicTest3=dicTest1.Union(test2);
foreach(var keyValuePair in dicTest3)
{
Console.WriteLine("{0}:{1}",keyValuePair.Key,keyValuePair.Value);
}
Console.ReadLine();
注意要using System.Linq 的nameSpace
另外如果不想去重的话 就用
dicTest1.Concat(test2);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询