我想为不同的帐户保留一些总计.在C++中我会像这样使用STL:
map<string,double> accounts;
// Add some amounts to some accounts.
accounts["Fred"] += 4.56;
accounts["George"] += 1.00;
accounts["Fred"] += 1.00;
cout << "Fred owes me $" << accounts['Fred'] << endl;
Run Code Online (Sandbox Code Playgroud)
现在,我将如何在C#中做同样的事情?
假设我有这个清单:
1 1 1 1 2 2 2 3
我想用C#将其缩小到一个列表中,列表中最多有两个相同的项目,所以它看起来像这样:
1 1 2 2 3
我曾经像这样使用'distinct':
string[] array = System.IO.File.ReadAllLines(@"C:\list.txt");
List<string> list = new List<string>(array);
List<string> distinct = list.Distinct().ToList();
Run Code Online (Sandbox Code Playgroud)
但是不知道如何才能带来最大数量的相同值