将列表转换为字符串 [英] coneverting list in to string
本文介绍了将列表转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试以下操作,但出现错误无法将类型"string"隐式转换为"System.Collections.Generic.Dictionary< string,string>''''
I''m trying to do the follwoing but having an error " Cannot implicitly convert type ''string''to ''System.Collections.Generic.Dictionary<string,string>''"
public Dictionary<string,> ReasonErrorCodeList
{
set
{
if (_list.Count> 0)
{
foreach (KeyValuePair<string,> pair in _list)
{
_list.Add(pair.Key,"1234");
}
string x = _list.ToString();
//string y = _list.
infoMessage.Text = string.Format("the list is ",x);
infoPanel.Visible = true;
}
}
get {
//_list.Add (infoMessage.Text,"ERR_OOOOO1");
return infoMessage.Text;
}
}
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
protected global::System.Web.UI.WebControls.Literal infoMessage;
推荐答案
假定_list
是Dictionary<string, string>
,为什么要在其上调用ToString
?您认为这会给您带来什么?
同样在二传手中,您遍历字典并将项添加到自身(没有意义的事情).
get
方法中的错误是显而易见的.如果期望的返回类型为Dictionary<>
,则不能返回String
.
Assuming_list
is aDictionary<string, string>
why are you callingToString
on it? What do you think will that give you?
Also in the setter, you iterate through the dictionary and add items to itself (pointless thing to do).
The error in theget
-method is obvious. You cannot return aString
when the expected return type is aDictionary<>
.
这篇关于将列表转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文