练习 - 完成将字符串内插应用于套用信函的挑战

已完成

对于销售和营销公司的最新投资产品,你向公司的现有客户发送数千封个性化信件。 你的工作是编写 C# 代码以合并有关客户的个性化信息。 信中包含其现有投资组合等信息,并将当前回报与预计的回报进行比较,如果他们要投资使用新产品。

作者已决定使用以下示例市场营销消息。 下面是所需的输出(使用虚构的客户帐户数据)。

Dear Ms. Barros,
As a customer of our Magic Yield offering we are excited to tell you about a new financial product that would dramatically increase your return.

Currently, you own 2,975,000.00 shares at a return of 12.75%.

Our new product, Glorious Future offers a return of 13.13%.  Given your current volume, your potential profit would be ¤63,000,000.00.

Here's a quick comparison:

Magic Yield         12.75%   $55,000,000.00      
Glorious Future     13.13%   $63,000,000.00  

利用您新掌握的字符串格式化知识来开发一个应用程序,该应用程序能够根据前面的示例输出合并和格式化相应的内容。 请特别注意空格,并确保使用 C# 准确表示此确切格式。

  1. 选择并删除 Visual Studio Code 编辑器中的所有代码行。

  2. 在 Visual Studio Code 中,添加以下代码以获取挑战的数据:

    string customerName = "Ms. Barros";
    
    string currentProduct = "Magic Yield";
    int currentShares = 2975000;
    decimal currentReturn = 0.1275m;
    decimal currentProfit = 55000000.0m;
    
    string newProduct = "Glorious Future";
    decimal newReturn = 0.13125m;
    decimal newProfit = 63000000.0m;
    
    // Your logic here
    
    Console.WriteLine("Here's a quick comparison:\n");
    
    string comparisonMessage = "";
    
    // Your logic here
    
    Console.WriteLine(comparisonMessage);
    
  3. 使用 Visual Studio Code 编辑器在使用给定变量和代码时生成消息。

    除了注释之外,不得删除任何现有代码。

  4. 确保代码输出以下消息:

    Dear Ms. Barros,
    As a customer of our Magic Yield offering we are excited to tell you about a new financial product that would dramatically increase your return.
    
    Currently, you own 2,975,000.00 shares at a return of 12.75%.
    
    Our new product, Glorious Future offers a return of 13.13%.  Given your current volume, your potential profit would be $63,000,000.00.
    
    Here's a quick comparison:
    
    Magic Yield         12.75%   $55,000,000.00      
    Glorious Future     13.13%   $63,000,000.00  
    

祝你好运!

无论是遇到问题而需要查看解决方案,还是成功完成操作,都请继续查看此挑战的一种解决方案。