gpt4 book ai didi

c# - 如何在 StringTemplate 中创建 foreach? 。网

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:29 27 4
gpt4 key购买 nike

我必须创建这样的语句:

$foreach item in p.Beneficiaries$
BeneName $ai.Beneficiaries.IndexOf(item) + 1$ : item.Name
$end$

我必须做什么才能让它发挥作用?

最佳答案

StringTemplate 在迭代中为您提供了 $i$ 和 $i0$ 函数,这使您可以从 1 或 0 开始查看当前索引。使用基于 1 的索引函数 $i$ 你可以这样做:

Beneficiaries(p) ::= <<
$p.beneficiaries:{item | BeneName $i$ : $item.name$}; separator="\n"$
>>

产生以下输出:

BeneName 1 : Bob
BeneName 2 : Helen
BeneName 3 : Dave

编辑

刚刚注意到您在另一个集合上调用了 IndexOf,这使我的建议毫无用处。无论如何,我都会留下答案,以防有人觉得它有用。

关于c# - 如何在 StringTemplate 中创建 foreach? 。网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31741218/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com