0

所有这些代码都可以正常工作。我的问题是消息框中的变量 lTest,如何显示由逗号连接的列表结果。

List<int> lNetworkIds = new List<int>();
Dictionary<DisplayDay, int> numDayOccurances = new Dictionary<DisplayDay, int>();

foreach (Proposal lDetail in this._Proposal.Details)
{
    if (!lNetworkIds.Contains(lDetail.NetworkId))
        lNetworkIds.Add(lDetail.NetworkId);
    if (!numDayOccurances.ContainsKey(lDetail.Day))
        numDayOccurances[lDetail.Day] = 0;
    numDayOccurances[lDetail.Day]++;
}

if (numDayOccurances.Count > 0)
{ 

    string lTest = "";
    foreach (DisplayDay myday in numDayOccurances.Keys)
    {

        lTest += myday.ToString();
    }

    MessageBox.Show(lTest);

}
4

3 回答 3

5

代替foreach, 使用:

string lTest = String.Join(",", numDayOccurances.Keys);
于 2013-11-07T15:40:26.290 回答
3

您需要为此使用 String.Join():http: //msdn.microsoft.com/en-us/library/57a79xd0.aspx

于 2013-11-07T15:38:50.923 回答
1

尝试这个:

var lTest = string.Join(", ", numDayOccurances.Select(e=>e.Key.ToString()));
于 2013-11-07T15:43:47.327 回答