用方法的输出替换文本框中的任何索引

Replace any index in a text frame with output of a method

我为列表中的每个人设计了一个消息框架,其中包含一些索引。就像下面的那个:

  Dear {0} 
  Hi, 
  the total amount of Draft is {1}.
  amount of prm is {2}
  yesterday amount is {3} 

我写了一个方法 return 所有不同类型的金额并将方法的输出插入到列表中。我想用正确的数量替换每个文本框项目。

例如如下所示的输出:

促销 拒绝金额 伤害量
1230 56555 79646354

我的方法如下:

     public List<outputList1> listAmount()
    {

        var amounts = (from p in db.FactTotalAmount
                       
                       group p by p.FromDate  into g
                         select new outputList1
                         {

                             YesterdaySalesPrm = g.Sum(x => 
                               x.YesterdaySalesPrm),
                             YesterdayDraftAmount = g.Sum(x => 
                              x.YesterdayDraftAmount),
                             PrmSales = g.Sum(x => x.PrmSales),
                             DraftAmount = g.Sum(x => x.DraftAmount)
                         }).ToList();

        return amounts;
    }

你能帮我看看我该怎么做吗

我来教你钓鱼

使用模板构建字符串的主要方法有两种 - 格式化和插值。

选项一:使用string.Format:

string output = string.Format("Today is {0}. Weather is {1} at {2}°.", "Monday", "rain", 75.2);
// result is "Today is Monday. Weather is rain at 75.2°."

选项二:使用 C# 6 string interpolation:

string dayOfWeek = "Monday";
string weather = "rain";
decimal temp = 75.2;

// Notice the "$" at the start of the string literal
string output = $"Today is {dayOfWeek}. Weather is {weather} at {temp}°.";

所以,您有一个模型 - 您收集的数据 - 和一个格式字符串。将这些与这些选项之一组合在一起以生成最终输出字符串。