如何把一个Dictionary对象的键值都取出来,然后拼接到一起,达到string str=key1+value1+key2+value2+··
3个回答
展开全部
StringBuilder sb = new StringBuilder();
Dictionary<string, string> dict = new Dictionary<string, string>();
//...添加键值操作
foreach (var kv in dict)//如果是.NET2.0 var换成KeyValuePair<string,string>
{
sb.AppendFormat("{0}{1}", kv.Key, kv.Value);
}
string str = sb.ToString();
Dictionary<string, string> dict = new Dictionary<string, string>();
//...添加键值操作
foreach (var kv in dict)//如果是.NET2.0 var换成KeyValuePair<string,string>
{
sb.AppendFormat("{0}{1}", kv.Key, kv.Value);
}
string str = sb.ToString();
展开全部
比如
Dictionary<int, string> dic = new Dictionary<int, string>();
dic.Add(1, "1");
dic.Add(2, "2");
dic.Add(3, "3");
string str = "";
foreach (int strvalue in dic.Keys)
{
str += strvalue.ToString() + dic[strvalue].ToString();
}
Response.Write(str);
Dictionary<int, string> dic = new Dictionary<int, string>();
dic.Add(1, "1");
dic.Add(2, "2");
dic.Add(3, "3");
string str = "";
foreach (int strvalue in dic.Keys)
{
str += strvalue.ToString() + dic[strvalue].ToString();
}
Response.Write(str);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class MyListBox: ListBox
{
public int SelectedCount()
{
int a = this.Items.Count;
int all = 0;
for (int i = 0; i < a; i++)
{
if (list.Items[i].Selected)
{
all++;
}
}
return all;
}
}
{
public int SelectedCount()
{
int a = this.Items.Count;
int all = 0;
for (int i = 0; i < a; i++)
{
if (list.Items[i].Selected)
{
all++;
}
}
return all;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询