我在 MessageBox 中的结果lTest
由字符串连接。如果我有重复的键,如何按键(值)对它们进行分组?例如,如果星期一出现四次,星期二出现一次,而不是星期一、星期一、星期一、星期一、星期二。我希望它出现在星期一(4),星期二(1)。
List<int> lNetworkIds = new List<int>();
Dictionary<DisplayDay, int> numDayOccurances = new Dictionary<DisplayDay, int>();
StringBuilder sb = new StringBuilder();
// get a list of distinct network id's for this proposal
foreach (Proposal lDetail in this._Proposal.Details)
{
if (!lNetworkIds.Contains(lDetail.NetworkId))
lNetworkIds.Add(lDetail.NetworkId);
if (!numDayOccurances.ContainsKey(lDetail.Daypart))
numDayOccurances[lDetail.Daypart] = 0;
numDayOccurances[lDetail.Daypart]++;
}
if (numDayOccurances.Count > 0)
{
string lTest = String.Join(", ", numDayOccurances.Keys);
MessageBox.Show(lTest);
}