开发者社区> 问答> 正文

C#等效于C ++ map <string,double>

我想保留不同帐户的总计。在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; 现在,我将如何在C#中执行相同的操作? 问题来源于stack overflow

展开
收起
保持可爱mmm 2020-02-09 13:56:22 514 0
1 条回答
写回答
取消 提交回答
  • 大致:-

    var accounts = new Dictionary<string, double>();

    // Initialise to zero...

    accounts["Fred"] = 0; accounts["George"] = 0; accounts["Fred"] = 0;

    // Add cash. accounts["Fred"] += 4.56; accounts["George"] += 1.00; accounts["Fred"] += 1.00;

    Console.WriteLine("Fred owes me ${0}", accounts["Fred"]);

    2020-02-09 13:56:51
    赞同 展开评论 打赏
问答分类:
C#
问答地址:
问答排行榜
最热
最新

相关电子书

更多
使用C++11开发PHP7扩展 立即下载
GPON Class C++ SFP O;T Transce 立即下载
GPON Class C++ SFP OLT Transce 立即下载

相关实验场景

更多