如何把Dictionary<string, string>()中的数据添加到哈希表中????
如何把Dictionary<string, string>()中的数据添加到哈希表中???? --------------------编程问答--------------------using System;--------------------编程问答-------------------- 遍历foreach (KeyValuePair<int, int> item in dic)
using System.Data;
using System.Collections;
using System.Collections.Generic;
class Test
{
static void Main()
{
Dictionary<int, int> diclist = new Dictionary<int, int>();
diclist.Add(1, 10);
diclist.Add(2, 20);
diclist.Add(3, 30);
diclist.Add(4, 40);
Hashtable hashtable = new Hashtable();
foreach (KeyValuePair<int, int> item in diclist)
{
hashtable.Add(item.Key, item.Value);
}
foreach (DictionaryEntry hash in hashtable)
{
Console.WriteLine(hash.Key.ToString() + "-" + hash.Value.ToString());
}
Console.ReadLine();
}
}
{
//item.Key, item.Value
}
或使用LINQ 遍历
hashtable.add
--------------------编程问答-------------------- --------------------编程问答--------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>--------------------编程问答-------------------- 答案回复错误,恢复到另外一个帖子了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org啊/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form runat="server" id="form1">
<asp:TextBox ID="txt" runat="server" />
<asp:TextBox ID="TextBox1" runat="server" />
<asp:TextBox ID="TextBox2" runat="server" />
<asp:TextBox ID="TextBox3" runat="server" />
<asp:TextBox ID="TextBox4" runat="server" />
<asp:TextBox ID="TextBox5" runat="server" />
</form>
</body>
</html>
\using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
//using System.Text.RegularExpressions;
protected void Page_Load(object sender, EventArgs e)
{
Hashtable hash = new Hashtable();
hash.Add("TextBox1", "1");
hash.Add("TextBox2", "2");
hash.Add("TextBox3", "3");
foreach (DictionaryEntry item in hash)
{
try
{
((TextBox)form1.FindControl(item.Key.ToString())).Text = item.Value.ToString();
}
catch
{
}
}
}
}
http://topic.csdn.net/u/20110302/17/c71a29b3-f156-4368-9b61-0cfc69475dd1.html?seed=784685788&r=71904609#r_71904609 --------------------编程问答-------------------- 本来泛型就用来代替非泛型集合的。
你倒是倒退。 --------------------编程问答-------------------- 循环遍历就可以啦!
补充:.NET技术 , C#